﻿using Aspose.Cells;
using BarcodeDelay.bean;
using BarcodeDelay.business;
using BarcodeDelay.FrameDecoder;
using BarcodeDelay.FrameServer;
using BarcodeDelay.HttpClient;
using BarcodeDelay.logHelp;
using BarcodeDelay.Transaction;
using BarcodeDelay.utility;
using BarcodeDelay.view;
using BeetleX.FastHttpApi;
using JTParcrelHelper.bean;
using JTParcrelHelper.business;
using JTParcrelHelper.MessageClient;
using JTParcrelHelper.view;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BarcodeDelay
{
    public partial class FrmMainNew : Form
    {
        private delegate void SetPos(int ipos, int total, string strStationName, string strType);
        ArrayList m_arListArrivalBarcodes = new ArrayList();
        ArrayList m_arListDepartureBarcodes = new ArrayList();

        ArrayList m_arListDisplayBarcodes = new ArrayList();

        ArrayList m_arListManualLeaveBarcodes = new ArrayList();

        ArrayList m_arListFruiteBarcodes = new ArrayList();
        DataTable m_dt_ArrivalDelayed = new DataTable();
        DataTable m_dt_DepartureDelayed = new DataTable();
        DataTable m_dt_FruitDelayed = new DataTable();
        DataTable m_dt_copy = new DataTable();

        DataTable m_dt_LasnhouFail = new DataTable();

        private Hashtable m_htRoadMap = new Hashtable();
        private Hashtable m_htDepRoadMap = new Hashtable();
        private Hashtable m_htFruitRoadMap = new Hashtable();
        private Hashtable m_ht_arr_filter = new Hashtable();
        private Hashtable m_ht_fruit_filter = new Hashtable();
        BindingSource mbs_arrival = new BindingSource();
        BindingSource mbs_departure = new BindingSource();
        BindingSource mbs_fruit = new BindingSource();
        BindingSource mbs_copy = new BindingSource();

        BindingSource mbs_lanshouFail = new BindingSource();

        public StreamWriter swb = null;
        FileStream bFile = null;
        FrmRigister frmRigister = new FrmRigister();
        
        private static object obj_arri = new object();
        private static object obj_fruit = new object();
        private delegate void RefreshDgv();
        private int exportTime = 1;
        Hashtable m_htCopyMap = new Hashtable();
        private int countTime = 0;
        private int addMessageCount = 0;
        private int anylizeWaybillCount = 0;
        private Hashtable m_ht_dep_filter = new Hashtable();
        private bool isFirstStart = true;

        private bool isUsing4Delay = false;
        private StringBuilder sbZC = new StringBuilder();
        int totalCount = 0;
        StringBuilder sbcInter = new StringBuilder();

        public bool isClickManual = false;

        private string lastRecContent = "";
        public ArrayList arListLanShouFail = new ArrayList();

        public string m_gewei = "";
      
        public FrmMainNew()
        {
            
            //string m = System.DateTime.Now.ToString("hh:mm:ss.fff");
            //string a = "导出待跟踪单号 日期:2022-10-31";
            //UtilityHelp.Instance.getDateTime(a);
            StoParams.Instance.initParam();
            InitializeComponent();

            string macInfo = UtilityHelp.Instance.GetMACAddress();
            /*if(macInfo!= "701CE76492BD")
            {
                this.Close();
            }*/

            JTDelayHelperNew.Instance.DoneDepAnay += Instance_Departure_DoneAnay;
            JTDelayHelperNew.Instance.DoneDepCount += Instance_DoneDepCount;


            LeaveMessageHelperAssignDelay.Instance.DoneHttpResponse += Instance_DoneHttpResponse;
            LeaveMessageHelperAssignDelay.Instance.GotDelayBarcode += Instance_GotDelayBarcode;
            LeaveMessageHelperAssignDelay.Instance.GotFailedBarcode += Instance_GotFailedBarcode;

            JTDelayHelperNew.Instance.DoneHttpResponse += Instance_DoneHttpResponse;

            JTDelayHelperNew.Instance.DoneSBResponse += Instance_DoneSBResponse;

            LeaveMessageHelperAuto.Instance.DoneSBResponse += Instance_DoneSBResponse;
            LeaveMessageHelperAuto.Instance.DoneHttpResponse += Instance_DoneHttpResponseAuto;

            LeaveMessageHelperGen.Instance.GotDelayBarcode += Instance_GotDelayBarcode;
            LeaveMessageHelperGen.Instance.GotFailedBarcode += Instance_GotFailedBarcode;
            LeaveMessageHelperGen.Instance.DoneHttpResponse += Instance_DoneHttpResponseAuto;

            LeaveMessageHelperGen.Instance.AddMessage += Instance_AddMessage;
            LanshouHelperGen.Instance.AddMessage += Instance_AddMessage;

            GetMsgBoardHelperGen.Instance.doneExpotEvent += Instance_doneExpotEvent;

            
            LeaveMessageHelperGen.Instance.QueryMessageRes += Instance_QueryMessageRes;
            LeaveMessageHelperAuto.Instance.QueryMessageRes += Instance_QueryMessageResAuto;
            LeaveMessageHelperAuto.Instance.GotDelayBarcode += Instance_GotDelayBarcode;
            LeaveMessageHelperAuto.Instance.GotFailedBarcode += Instance_GotFailedBarcode;


            LoadBasicHelper.Instance.QueryDataBasicRes += Instance_QueryDataBasicRes;
            DelayAnaHelperGen.Instance.DoneArrOrDepAnay += Instance_DoneArrOrDepAnay;


            InterceptMessageHelper.Instance.DoneHttpResponse += Instance_DoneHttpResponseIntercepted;


            InboundSignMessageHelper.Instance.SignSucessBarcode += Instance_SignSucessBarcode;
            InboundSignMessageHelper.Instance.DoneHttpResponse += Instance_DoneHttpResponseAuto;
            InboundSignMessageHelper.Instance.SignFailedBarcode += Instance_SignFailedBarcode;

            CuiJianMessageHelper.Instance.DoneHttpResponse += Instance_DoneHttpResponseIntercepted;
            InterceptMessageHelper.Instance.GotInterceptBarcode += Instance_GotInterceptBarcode;
            LeaveMessageHelperAuto.Instance.GotInterceptBarcode += Instance_GotInterceptBarcode;
            MemberInfo.Instance.DoneMemInfo += Instance_DoneMemInfo;
            frmRigister.DoneRegInfo += Instance_DoneMemInfo;
            MemberInfo.Instance.initMember();
            init();
            readPath();
            bFile = new FileStream("log.txt", FileMode.Create);
            if (swb == null)
            {
                swb = new StreamWriter(bFile);
            }
            if (StoParams.Instance.register_site != "")
            {
                MemberInfo.Instance.BeginMemThread();
            }

           
            if (StoParams.Instance.superWechatFlag.Contains("server"))
            {
                Program.weServer.BuildServer();
            }
            
            FrameDecoderManager.Instance.DoneSBResponse += Instance_DoneSBResponse1;
            ChangeAddrHelperGen.Instance.changeAddr += Instance_changeAddr;
            WeightHelperGen.Instance.weightEvent += Instance_weightEvent;
            CancelInterHelperGen.Instance.CancelsEvent += Instance_CancelsEvent;
            FrameDecoderManager.Instance.curExcuteStep += Instance_curExcuteStep;

            //MessageHandleManager.Instance.curExcuteStep += Instance_curExcuteStep;

            ZhongCaiHelperGen.Instance.zhongcaiEvent += Instance_zhongcaiEvent;


            LanshouHelperGen.Instance.OnMessageResultEvent += Instance_OnMessageResultEvent;


            LanshouFailGen.Instance.AddMessage += Instance_AddMessage_lanshouFail;
            LanshouFailGen.Instance.OnMessageResultEvent += Instance_OnMessageResultEvent;


            FajianHelperGen.Instance.OnMessageResultEvent += Instance_OnMessageResultEvent;
            FajianHelperGen.Instance.AddMessage += Instance_AddMessage_lanshouFail;

            if (StoParams.Instance.superWechatFlag.Contains("server"))
            {
                startHttpPort();
            }
                
            if (StoParams.Instance.superWechatFlag.Contains("client"))
            {
                initProClient();
            }
            MessageProClient.Instance.OnMessageEvent += Instance_OnMessageEvent;

            MessageQQProClient.Instance.OnMessageEvent += Instance_OnMessageEvent;

            MessageProClient.Instance.OnStationConnectEvent += Instance_OnStationConnectEvent;

            MessageQQProClient.Instance.OnStationConnectEvent += Instance_OnStationQQConnectEvent;

            ZCMessageHelperInfo.Instance.DoneHttpResponse += Instance_DoneHttpResponse1;

            TerminalMessageHelperInfo.Instance.DoneHttpResponse += Instance_DoneHttpResponse2;

            //this.Text = this.Text +" "+StoParams.Instance.regAllSites;

            //string a = "";
            //UtilityHelp.Instance.genStaticExcel(out a,"测试客服", "统计跟单2022-11-08");
            //string cur = "{\"code\":1,\"msg\":\"请求成功\",\"data\":{\"loginTime\":\"2022-12-18 18:33:12\",\"status\":0,\"uuid\":\"02f064b960fa47fba7286faa9fbc5da4\",\"token\":\"02f064b960fa47fba7286faa9fbc5da4\",\"id\":1556125,\"name\":\"钟东妹\",\"staffNo\":\"00784382\",\"networkId\":4623927,\"networkCode\":\"1759179\",\"networkName\":\"湛江廉江新网点\",\"userType\":1,\"institutionalLevelId\":336,\"institutionalLevelDesc\":\"网点\",\"financialCenterId\":616,\"financialCenterDesc\":\"粤西代理区\",\"financialCenterCode\":\"440002\",\"isFinancialCenter\":2,\"isDistributionCenter\":2,\"isFirstFranchisee\":2,\"isSecondFranchisee\":2,\"isEntrepot\":2,\"sex\":2,\"deptName\":\"网点人员\",\"postName\":\"网点客服\",\"ip\":\"14.119.180.136\",\"loginType\":1,\"appType\":1,\"mobile\":\"13823487080\",\"phone\":\"\",\"email\":null,\"alertMsg\":0,\"msgAudio\":0,\"position\":null,\"franchiseeId\":4623888,\"franchiseeCode\":\"440002262\",\"franchiseeName\":\"湛江加盟商五(梁树茂湛江廉江)\",\"configColor\":null,\"configLanguage\":null,\"pcLoginDevice\":\"14.119.180.136\",\"sysResourceTree\":[{\"id\":541,\"cnName\":null,\"enName\":\"基础资料\",\"name\":\"基础资料\",\"routeName\":\"basicInformationIndex\",\"path\":\"\",\"component\":\"\",\"menuUrl\":\"\",\"code\":\"BASICINFO\",\"deptLevelId\":336,\"deptLevelName\":\"网点\",\"menuIcon\":\"iconshouye-jichushuju\",\"type\":\"\",\"parentCode\":\"0\",\"moduleType\":1,\"children\":[{\"id\":580,\"cnName\":null,\"enName\":\"zuzhijiagou\",\"name\":\"组织架构\",\"routeName\":\"\",\"path\":\"\",\"component\":\"\",\"menuUrl\":\"\",\"code\":\"ORGANIZATIONAL_STRUCTURE\",\"deptLevelId\":336,\"deptLevelName\":\"网点\",\"menuIcon\":\"iconzuzhijiegou\",\"type\":\"\",\"parentCode\":\"BASICINFO\",\"moduleType\":2,\"children\":[{\"id\":21294,\"cnName\":null,\"enName\":\"\",\"name\":\"员工优先调度配置\",\"routeName\":\"staffPrimaryDispatchConfig\",\"path\":null,\"component\":null,\"menuUrl\":\"/basicdata/network/select,\n/basicdata/sysStaffSchedule/page,\n/basicdata/sysStaffSchedule/changePriorityScheduleStatus\",\"code\":\"STAFF_PRIMARY_DISPATCH_CONFIG\",\"deptLevelId\":336,\"deptLevelName\":\"网点\",\"menuIcon\":\"\",\"type\":null,\"parentCode\":\"ORGANIZATIONAL_STRUCTURE\",\"moduleType\":3,\"children\":[{\"id\":21296,\"cnName\":null,\"enName\":\"\",\"name\":\"导出\",\"routeName\":null,\"path\":null,\"component\":null,\"menuUrl\":\"/basicdata/sysStaffSchedule/exportData,\n/basicdata/exportTa";
            //string cur = "JT5209185211996  凯弘 转54336[8985]17281476338福建省厦门市海沧区 收件人：凯弘转54336手机号码：18820473063收件地址：福建省厦门市海沧区东孚街道前场北路象屿智慧产业园北区1栋204 - 11号凯弘转（会员ID + 会员账号）（凯弘集运）邮编：361026[8985]\n修改地址收件人：凯弘转\nollllollllo（543360手机号码：18820473063\n\n收件地址：福建省厦门市海沧区囷瑶路88号仓库A区6号210（凯弘集运）（54336 + ollllollllo）\n邮编：361026";
            //string content = "[{\"tolist\":[\"wmhApKawAAOalu4ZLIxBnyos_Oh9EK0g\",\"wmhApKawAAtiHlc37xT8qe8bQNdNHcCg\",\"wmhApKawAAgEke3_WV9KLFzEHgisEuJA\",\"wmhApKawAA7okraEPyeBMwahrsHH9FyA\",\"wmhApKawAAtJ2MTL84mKgTkfOHncJrmQ\",\"wmhApKawAAC7aCDxqWVNtmCo6XMzGQRQ\",\"wmhApKawAAPATWKQJV94wjtksWNqUnfw\",\"wmhApKawAAm-BomYKHW-V0mSgn_Sjmfw\",\"wmhApKawAANPnYPymtIUGgOu3AOLU_gA\",\"wmhApKawAAfdivxq-O7IzM1o3kpPtpfA\",\"wmhApKawAAKZcUS5ktpCjQoc0xLbeCpg\",\"wmhApKawAAslmZ7hBHeShhD8LrDxfp9g\",\"wmhApKawAAobwfKcPTjerX-6NdmxsfhA\",\"wmhApKawAAnKQHQnCDHo8PmEqkteVONg\",\"wmhApKawAAFA3p-YVqcSB39c3qN7Y52Q\",\"WangJunCai\"],\"msgtime\":1677499745901,\"msgid\":\"15569976139509027841_1671113017672_external\",\"action\":\"send\",\"from\":\"wmhApKawAAiClNDrwJDA3QwLxLkoBXqQ1\",\"text\":{\"content\":\"" + cur+ "\"},\"msgtype\":\"text\",\"roomid\":\"wrhApKawAA-Bl1rHYwSQWxdgHbrpT0JQ\"}]";
            string cur = "";

            string timestamp = DateTimeToStamp(System.DateTime.Now.AddMinutes(0));
            string content = "[{\"tolist\":[\"wmhApKawAAS3vzGUmPOFS7UY4xTVcy8g\",\"wmhApKawAAuXqzDKJyDCKAm734fN_zbA\",\"wmhApKawAAym2MJ-BasuqjnwTj_wYcug\",\"wmhApKawAAM1B8yWtvvSYZNEGbMPnV4g\",\"wmhApKawAAtJ2MTL84mKgTkfOHncJrmQ\",\"wmhApKawAAC7aCDxqWVNtmCo6XMzGQRQ\",\"wmhApKawAAPATWKQJV94wjtksWNqUnfw\",\"wmhApKawAAm-BomYKHW-V0mSgn_Sjmfw\",\"wmhApKawAANPnYPymtIUGgOu3AOLU_gA\",\"wmhApKawAAfdivxq-O7IzM1o3kpPtpfA\",\"wmhApKawAAKZcUS5ktpCjQoc0xLbeCpg\",\"wmhApKawAAslmZ7hBHeShhD8LrDxfp9g\",\"wmhApKawAAobwfKcPTjerX-6NdmxsfhA\",\"wmhApKawAAnKQHQnCDHo8PmEqkteVONg\",\"wmhApKawAAFA3p-YVqcSB39c3qN7Y52Q\",\"WangJunCai\"],\"msgtime\":"+ timestamp + ",\"msgid\":\"15569976139509027841_1671113017672_external\",\"action\":\"send\",\"from\":\"wmhApKawAAiClNDrwJDA3QwLxLkoBXqQ\",\"text\":{\"content\":\"" + cur + "\"},\"msgtype\":\"text\",\"roomid\":\"49228368507@chatroom\"}]";
            string barcode = "JT2920578552044";

            //List<string>  test=UtilityHelp.Instance.GetTelephoneList(content, barcode);
            string a = @"";
            string b = "";
            string time = "12:00:23";
            DateTime dt = Convert.ToDateTime(time);

            string addr = cur;

             
            WechatMsgBean w8 = new WechatMsgBean();
            w8.content = cur;
            w8.roomid = "R:108543144510796132";
            w8.from = "168885755839706788";
            w8.isSuperWay = true;
           



            string cc = "{\"appinfo\":\"5143245825127902559\"}";
            JObject dataRes = (JObject)JsonConvert.DeserializeObject(cc);
            JArray atList = (JArray)dataRes["at_list"];

            string emsRegexStr = "^(9)[0-9]{12}$";
            Regex emsRegex = new Regex(emsRegexStr);
            string barcode2 = "9749767606164";
            if (emsRegex.IsMatch(barcode2))
            {
                int a2 = 0;
            }
            string amp = "{\"ServiceName\":\"wechatMsg\",\"roomid\":\"R:10854314451079613\",\"content\":\"\",\"msgtime\":\"\",\"msgtype\":\"\",\"from\":\"1688857558397070\",\"isQQ\":false,\"MQ_robot\":\"\",\"filename\":\"585081JY198波点甜甜圈绿.tif\",\"atUserList\":[]}";
            //handleTaskWechatMsg(amp);
           // string chineseStr = UtilityHelp.Instance.GetChineseCharacters(w8.content);
            //w8.content = w8.content.Replace(chineseStr, "");
            FrameDecoderManager.Instance.parseCompanyTcpWechat("", out b, w8);

        }

        private void Instance_DoneHttpResponse2()
        {
            if (StoParams.Instance.curParces >= totalCount)
            {
                txtCurrentStatus.BeginInvoke(new Action(() => {

                    txtCurrentStatus.Text = "已完成";

                }));
            }
            txbCurProcess.BeginInvoke(new Action(() => {

                double percent = (double)StoParams.Instance.curParces / totalCount;
                string percentText = percent.ToString("0.0%");
                txbCurProcess.Text = percentText;
            }));
            txtDelayHeader.BeginInvoke(new Action(() =>
            {
                if (StoParams.Instance.resMsg == "")
                {
                    string barcode = StoParams.Instance.currentBarcode;
                }
                txtDelayHeader.Text = "运单号：" + StoParams.Instance.currentBarcode + " 结果:" + StoParams.Instance.httpResmsg;
                if (StoParams.Instance.httpResmsg.Contains("所有单号执行完成"))
                {
                    genExceTerminalInfo();
                }

            }));
        }

        private void Instance_DoneHttpResponse1()
        {


            if (StoParams.Instance.curParces >= totalCount)
            {
                txtCurrentStatus.BeginInvoke(new Action(() => {

                    txtCurrentStatus.Text = "已完成";

                }));
            }
            txbCurProcess.BeginInvoke(new Action(() => {

                double percent = (double)StoParams.Instance.curParces / totalCount;
                string percentText = percent.ToString("0.0%");
                txbCurProcess.Text = percentText;
            }));
            txtDelayHeader.BeginInvoke(new Action(() =>
            {
                if (StoParams.Instance.resMsg == "")
                {
                    string barcode = StoParams.Instance.currentBarcode;
                }
                txtDelayHeader.Text = "运单号：" + StoParams.Instance.currentBarcode + " 结果:" + StoParams.Instance.httpResmsg;
                if (StoParams.Instance.httpResmsg.Contains("所有单号执行完成"))
                {
                    genExcelZcInfo();
                }

            }));
        }




        private void genExceTerminalInfo()
        {
            try
            {
                string outPath = txtOutput.Text + "\\" + System.DateTime.Now.ToString("yyyyMMddHHmm") + "末端对比统计.xlsx";
                bool res = UtilityExcel.Instance.GenExcelForStaticTerminal(JTDelayHelperNew.Instance.m_arlist_Delayed_BarCodes, outPath);
                if (res)
                {
                    TerminalMessageHelperInfo.Instance.exportExcel = true;
                    MessageBox.Show("统计成功 文件路径 " + txtOutput.Text);
                }
                else
                {
                    MessageBox.Show("统计失败 ");
                }
            }
            catch (Exception ex)
            {

            }
        }

        private void genExcelZcInfo()
        {
            try
            {
                string outPath = txtOutput.Text + "\\" + System.DateTime.Now.ToString("yyyyMMddHHmm") + "仲裁统计.xlsx";
                bool res = UtilityExcel.Instance.GenExcelForStaticZc(JTDelayHelperNew.Instance.m_arlist_Delayed_BarCodes, outPath);
                if (res)
                {
                    ZCMessageHelperInfo.Instance.exportExcel = true;
                    MessageBox.Show("统计成功 文件路径 " + txtOutput.Text);
                }
                else
                {
                    MessageBox.Show("统计失败 ");
                }
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_OnMessageFailResultEvent(object sender, EargsMessageResult e)
        {
            throw new NotImplementedException();
        }

        private void Instance_OnMessageResultEvent(object sender, EargsMessageResult e)
        {
            try
            {
                if(e.MessageKey.ToString().ToLower().Contains("fail"))
                {
                    arListLanShouFail = (ArrayList)e.Message;
                    if (arListLanShouFail.Count>0)
                    {
                       
                        updateFailList();
                        UpdateLanshouInfo(arListLanShouFail.Count,true);
                    }
                    
                }
                else
                {
                    arListLanShouFail = (ArrayList)e.Message;
                    updateSuccessList(arListLanShouFail);
                    UpdateLanshouInfo(arListLanShouFail.Count, false);
                }
            }
            catch(Exception ex)
            {

            }
        }



        private void Instance_doneExpotEvent()
        {
            try
            {
                if(isClickManual)
                {
                    MessageBox.Show("文件已生成，请到 " + StoParams.Instance.outputDir + " 目录查看生成文件");
                }
                
            }
            catch(Exception ex)
            {

            }
        }

        public  string DateTimeToStamp(DateTime now)
        {
            DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0)); // 当地时区
            long timeStamp = (long)(now - startTime).TotalMilliseconds; // 相差毫秒数
            return timeStamp.ToString();
        }


        private void updateSuccessList(ArrayList arListBaroces)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                foreach(string barcode in arListBaroces)
                {
                    sb.AppendLine(barcode);
                }
                tztLSSuccess.BeginInvoke(new Action(() =>
                {
                    tztLSSuccess.Text = tztLSSuccess.Text + "\r\n" + sb.ToString();
                }));
            }
            catch (Exception ex)
            {

            }
        }
        
        private void UpdateLanshouInfo(int failCount,bool isFail)
        {
            try
            {
                txtLSInfo.BeginInvoke(new Action(() =>
                {
                    string append= " 揽收失败数量：" + failCount.ToString();
                    if (!isFail)
                    {
                        append = " 揽收成功数量：" + failCount.ToString();
                    }
                    txtLSInfo.Text = txtLSInfo.Text + " "+ append;
                }));
            }
            catch (Exception ex)
            {

            }
        }


        private void updateFailList()
        {
            try
            {
                try
                {

                    if (dgvFail.InvokeRequired)
                    {
                        RefreshDgv c = new RefreshDgv(updateFailList);
                        if (this.IsHandleCreated)
                        {
                            this.Invoke(c);
                        }
                    }
                    else
                    {
                        lock (StoParams.Instance.obj_dep)
                        {
                            //Instance_DelayEvent();
                            Hashtable ht = StoParams.Instance.htLanshouFail;
                            if (ht.Count > 0)
                            {
                                string strDelayed = "";
                                foreach (string strBarcode in arListLanShouFail)
                                {
                                    if (ht.ContainsKey(strBarcode))
                                    {
                                        string failMsg = ht[strBarcode].ToString();
                                        DataRow drNew = m_dt_LasnhouFail.NewRow();
                                        drNew[0] = strBarcode;
                                        drNew[1] = failMsg;


                                        m_dt_LasnhouFail.Rows.Add(drNew);
                                        strDelayed = strDelayed + strBarcode + "\r\n";
                                        m_ht_dep_filter[strBarcode] = "";
                                    }
                                }

                                dgvFail.BeginInvoke(new Action(() =>
                                {
                                    mbs_lanshouFail = new BindingSource();
                                    mbs_lanshouFail.DataSource = m_dt_LasnhouFail;
                                    dgvFail.DataSource = mbs_lanshouFail;
                                    for (int i = 0; i < m_dt_LasnhouFail.Columns.Count; i++)
                                    {
                                        //this.dgvDelays.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                        this.dgvFail.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                                        this.dgvFail.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                        if (i == 0)
                                        {
                                            this.dgvFail.Columns[i].Width = 100;
                                            this.dgvFail.Columns[i].ReadOnly = true;
                                           
                                            //this.dgvDelays.Columns[i].Width = 20;
                                        }
                                        if (i == 1)
                                        {
                                            this.dgvFail.Columns[i].Width = 180;
                                            this.dgvFail.Columns[i].ReadOnly = true;
                                            //this.dgvDelays.Columns[i].Width = 20;
                                        }
                                       

                                    }
                                }));


                            }
                        }
                    }


                }
                catch (Exception ex)
                {
                    //MessageBox.Show("Instance_Departure_DoneAnay " + ex.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }


        private void Instance_SignFailedBarcode()
        {
            try
            {
                txtFailedBarcodes.BeginInvoke(new Action(() =>
                {
                    txtFailedBarcodes.Text = txtFailedBarcodes.Text + "\r\n" + StoParams.Instance.curFailedBarcode;
                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_SignSucessBarcode()
        {
            try
            {
                txtLeavedBarcodes.BeginInvoke(new Action(() =>
                {
                    txtLeavedBarcodes.Text = txtLeavedBarcodes.Text + "\r\n" + StoParams.Instance.curDelayBarcode;
                }));
            }
            catch(Exception ex)
            {

            }
        }

        private void Instance_DoneDepCount()
        {
            try
            {
                /*lblDelayTotal.BeginInvoke(new Action(() =>
                {
                    lblDelayTotal.Text = JTDelayHelperNew.Instance.m_ht_departure_BarCodes.Count.ToString(); ;
                }));*/

                txbDelayT.BeginInvoke(new Action(() =>
                {
                    txbDelayT.Text = JTDelayHelperNew.Instance.m_ht_departure_BarCodes.Count.ToString();
                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_OnStationConnectEvent(object sender, EargsClientConnect e)
        {
            try
            {
                this.initRegMessage();
                Thread.Sleep(100);
                this.initSiteMessage();
            }
            catch(Exception ex)
            {

            }
        }


        private void Instance_OnStationQQConnectEvent(object sender, EargsClientConnect e)
        {
            try
            {
                this.initRegQQMessage();
                Thread.Sleep(100);
                this.initQQSiteMessage();
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_OnMessageEvent(object sender, EargsMessageReceives e)
        {
            try
            {
                string key = e.MessageKey;
                string msg = e.Message;
                if(lastRecContent== msg)
                {
                    //return;
                }
                lastRecContent = msg;
                JObject jsonObj = (JObject)JsonConvert.DeserializeObject(msg);
                JToken nameToken = jsonObj["ServiceName"];
                switch (nameToken.ToString())
                {
                    case "wechatMsg":
                        handleTaskWechatMsg(msg);
                        break;
                    case "ackWechatMsg":
                        handleAckWechatMsg(msg);
                        break;
                }
            }
            catch(Exception ex)
            {

            }
        }

        public void handleTaskWechatMsg(string msg)
        {
            try
            {
                
                JObject jsonObj = (JObject)JsonConvert.DeserializeObject(msg);
                JToken roomid = jsonObj["roomid"];
                JToken content = jsonObj["content"];
                JToken msgtime = jsonObj["msgtime"];
                JToken msgtype = jsonObj["msgtype"];
                JToken from= jsonObj["from"];
                JToken isQQ = jsonObj["isQQ"];

                JToken filename = jsonObj["filename"];

                JToken is_atmsg = jsonObj["is_atmsg"];


                JArray atUserList = (JArray)jsonObj["atUserList"];

                WechatMsgBean wechatMsgBean = new WechatMsgBean();
                wechatMsgBean.roomid = roomid.ToString();
                wechatMsgBean.content = content.ToString();
                wechatMsgBean.msgtime = msgtime.ToString();
                wechatMsgBean.msgtype = msgtype.ToString();
                wechatMsgBean.from = from.ToString();
                wechatMsgBean.isSuperWay = true;
                if(is_atmsg!=null)
                {
                    wechatMsgBean.isAtMsg = Convert.ToBoolean(is_atmsg.ToString());
                }
                if(filename!=null)
                {
                    wechatMsgBean.file = filename.ToString();
                }
                
                if (isQQ!=null&&isQQ.ToString().ToLower()=="true")
                {
                    wechatMsgBean.isQQ = true;
                    JToken robotQQ = jsonObj["MQ_robot"];
                    wechatMsgBean.robotQQ = robotQQ.ToString();

                }
                if(atUserList!=null)
                {
                    foreach(JToken userId in atUserList)
                    {
                        wechatMsgBean.atUserList.Add(userId.ToString());
                    }
                }
                 string lastTask = "";

               

                FrameDecoderManager.Instance.parseCompanyTcpWechat("", out lastTask, wechatMsgBean);

            }
            catch(Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("rec wechat server msg: ex" + ex.ToString());
            }
        }


        public void handleAckWechatMsg(string msg)
        {
            try
            {

                JObject jsonObj = (JObject)JsonConvert.DeserializeObject(msg);
                JToken roomid = jsonObj["roomid"];
                JToken content = jsonObj["content"];
                JToken msgtime = jsonObj["msgtime"];
                JToken msgtype = jsonObj["msgtype"];
                JToken from = jsonObj["from"];
                JToken isQQ = jsonObj["isQQ"];

                JToken filename = jsonObj["filename"];

                JArray atUserList = (JArray)jsonObj["atUserList"];

                WechatMsgBean wechatMsgBean = new WechatMsgBean();
                wechatMsgBean.roomid = roomid.ToString();
                wechatMsgBean.content = content.ToString();
                wechatMsgBean.msgtime = msgtime.ToString();
                wechatMsgBean.msgtype = msgtype.ToString();
                wechatMsgBean.from = from.ToString();
                wechatMsgBean.isSuperWay = true;
                if (filename != null)
                {
                    wechatMsgBean.file = filename.ToString();
                }

                if (isQQ != null && isQQ.ToString().ToLower() == "true")
                {
                    wechatMsgBean.isQQ = true;
                    JToken robotQQ = jsonObj["MQ_robot"];
                    wechatMsgBean.robotQQ = robotQQ.ToString();

                }
                if (atUserList != null)
                {
                    foreach (JToken userId in atUserList)
                    {
                        wechatMsgBean.atUserList.Add(userId.ToString());
                    }
                }
                string lastTask = "";


                logHelp.LogHelper.Instance.writeLog("begin send parseAckTcpWechat");
                FrameDecoderManager.Instance.parseAckTcpWechat("", out lastTask, wechatMsgBean);

            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("rec wechat server msg: ex" + ex.ToString());
            }
        }

        private void initProClient()
        {
            try
            {
                if(StoParams.Instance.superWechatFlag.Contains("client"))
                {
                    ServerTimeTickManager.Instance.ReadConfiguration();
                    ServerTimeTickManager.Instance.Init();
                    MessageProClient.Instance.ReadConfiguration();
                    MessageProClient.Instance.Init();

                    if(StoParams.Instance.transferQQ)
                    {
                        MessageQQProClient.Instance.ReadConfiguration();
                        MessageQQProClient.Instance.Init();
                    }
                }
                
            }
            catch(Exception ex)
            {

            }

        }
        private void startHttpPort()
        {
            try
            {
                HttpApiServer httpApiServer = new BeetleX.FastHttpApi.HttpApiServer();

                httpApiServer.Options.LogToConsole = true;//日志输出到命令行
                httpApiServer.Options.LogLevel = BeetleX.EventArgs.LogType.Debug;//日志输出级别
                httpApiServer.Options.Port = 8098;//监听端口
                httpApiServer.Register(typeof(BarcodeDelay.Program).Assembly);
                httpApiServer.Open();
                Console.Write(httpApiServer.BaseServer);
                Console.Read();
            }
            catch (Exception ex)
            {
                MessageBox.Show("web启动错误");
            }

        }

        private void Instance_zhongcaiEvent()
        {
            try
            {
                rchRoadMap.BeginInvoke(new Action(() =>
                {
                    sbZC.AppendLine(System.DateTime.Now.ToString("hh:mm:ss.fff") + " "+ StoParams.Instance.resMsg);
                    rchRoadMap.Text = sbZC.ToString();
                    //rchRoadMap.Text = rchRoadMap.Text + "\r\n" + StoParams.Instance.resMsg;
                }));
            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("Instance_zhongcaiEvent ex:" + ex.ToString());
            }
        }


        private void Instance_DelayEvent()
        {
            try
            {
                /*lblDelayTotal.BeginInvoke(new Action(() =>
                {
                    lblDelayTotal.Text = JTDelayHelperNew.Instance.m_ht_departure_BarCodes.Count.ToString(); ;
                }));*/
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_curExcuteStep()
        {
            try
            {
                rchRoadMap.BeginInvoke(new Action(() =>
                {
                    txtCurAutoBarcode.Text = StoParams.Instance.curHandleStep;
                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_CancelsEvent()
        {
            try
            {
                rchRoadMap.BeginInvoke(new Action(() =>
                {
                    rchRoadMap.Text = rchRoadMap.Text + "\r\n" + StoParams.Instance.resMsg;
                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_weightEvent()
        {
            try
            {
                rchRoadMap.BeginInvoke(new Action(() =>
                {
                    rchRoadMap.Text = rchRoadMap.Text + "\r\n" + StoParams.Instance.resMsg;
                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_changeAddr()
        {
            try
            {
                rchRoadMap.BeginInvoke(new Action(() =>
                {
                    rchRoadMap.Text = StoParams.Instance.resMsg;
                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_DoneSBResponse1()
        {
            try
            {
                rchRoadMap.BeginInvoke(new Action(() =>
                {
                    rchRoadMap.Text = StoParams.Instance.lastRecvContent;
                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_DoneSBResponse()
        {
            try
            {
                rchRoadMap.BeginInvoke(new Action(() =>
                {
                    rchRoadMap.Text = rchRoadMap.Text + "\r\n" + StoParams.Instance.resMsg;
                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_GotInterceptBarcode()
        {
            try
            {
                txtIntercetp.BeginInvoke(new Action(() =>
                {
                    sbcInter.AppendLine(StoParams.Instance.curInterCeptSuccess);
                    txtIntercetp.Text = sbcInter.ToString();
                    if(sbcInter.ToString().Length>66000)
                    {
                        sbcInter.Clear();
                    }


                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_GotFailedBarcode()
        {
            try
            {
                txtFailedBarcodes.BeginInvoke(new Action(() =>
                {
                    txtFailedBarcodes.Text = txtFailedBarcodes.Text + "\r\n" + StoParams.Instance.curFailedBarcode;
                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_GotDelayBarcode()
        {
            try
            {
                txtLeavedBarcodes.BeginInvoke(new Action(() =>
                {
                    txtLeavedBarcodes.Text = txtLeavedBarcodes.Text + "\r\n" + StoParams.Instance.curDelayBarcode;
                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_DoneHttpResponseIntercepted()
        {
            try
            {
                rchRoadMap.BeginInvoke(new Action(() =>
                {

                    if (rchRoadMap.Text == "")
                    {
                        rchRoadMap.Text = StoParams.Instance.interResMsg;
                    }
                    else
                    {
                        if (rchRoadMap.Text.Length > 512)
                        {
                            rchRoadMap.Text = "";
                        }
                        rchRoadMap.Text = rchRoadMap.Text + "\r\n" + StoParams.Instance.interResMsg;
                    }

                }));

                txtIntercetp.BeginInvoke(new Action(() =>
                {
                    if (StoParams.Instance.interResMsg.Contains("拦截成功"))
                    {
                        if (txtIntercetp.Text == "")
                        {
                            txtIntercetp.Text = StoParams.Instance.interBarcode;
                        }
                        else
                        {
                            txtIntercetp.Text = txtIntercetp.Text + "\r\n" + StoParams.Instance.interBarcode;
                        }
                    }


                }));
            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_DoneHttpResponseAuto()
        {
            try
            {
                lblTotal.BeginInvoke(new Action(() =>
                {
                    lblTotal.Text = StoParams.Instance.totalParcels.ToString();
                }));

                txtCurAutoBarcode.BeginInvoke(new Action(() =>
                {
                    if (StoParams.Instance.resMsg == "")
                    {
                        string barcode = StoParams.Instance.currentBarcode;
                    }

                    txtCurAutoBarcode.Text = "运单号：" + StoParams.Instance.currentBarcode + " 结果:" + StoParams.Instance.httpResmsg;
                }));
                lblQueryTotal.BeginInvoke(new Action(() =>
                {
                    lblQueryTotal.Text = StoParams.Instance.curParces.ToString();
                }));

                lblFinishPercent.BeginInvoke(new Action(() =>
                {
                    string strPercent = ((double)StoParams.Instance.curParces / (double)StoParams.Instance.totalParcels).ToString("P");
                    lblFinishPercent.Text = strPercent;
                }));

                lblAddCount.BeginInvoke(new Action(() =>
                {
                    lblAddCount.Text = StoParams.Instance.addCommentParcels.ToString();
                }));

            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_QueryMessageResAuto()
        {
            lblTotal.BeginInvoke(new Action(() =>
            {
                lblTotal.Text = StoParams.Instance.totalParcels.ToString();
            })); ;
        }

        private void Instance_DoneHttpResponse()
        {
            try
            {
                
                txtDelayHeader.BeginInvoke(new Action(() =>
                {
                    if (StoParams.Instance.resMsg == "")
                    {
                        string barcode = StoParams.Instance.currentBarcode;
                    }
                    txtDelayHeader.Text = "运单号：" + StoParams.Instance.currentBarcode + " 结果:" + StoParams.Instance.httpResmsg;
           
                }));

                if(StoParams.Instance.curParces>= totalCount)
                {
                    txtCurrentStatus.BeginInvoke(new Action(() =>                    {

                        txtCurrentStatus.Text = "已完成";
                    }));
                }
                txbCurProcess.BeginInvoke(new Action(() => {
                    
                    double percent = (double)StoParams.Instance.curParces / totalCount;
                    string percentText = percent.ToString("0.0%");
                    txbCurProcess.Text = percentText;
                }));
                
            }
            catch (Exception ex)
            {

            }

        }

        private void Instance_QueryDataBasicRes()
        {
            try
            {
                txtDelayHeader.BeginInvoke(new Action(() =>
                {
                    txtDelayHeader.Text = "完成：" + UtilityHelp.Instance.getProcess(StoParams.Instance.totalPages, StoParams.Instance.curPage);
                }));
            }
            catch (Exception ex)
            {

            }
        }



        private void Instance_QueryMessageRes()
        {
            try
            {
                rchRoadMap.BeginInvoke(new Action(() =>
                {
                    rchRoadMap.Text = StoParams.Instance.resMsg;
                }));


            }
            catch (Exception ex)
            {

            }
        }



        private void Instance_AddMessage_lanshouFail()
        {
            try
            {

                txtLSInfo.BeginInvoke(new Action(() =>
                {
                    txtLSInfo.Text = StoParams.Instance.resMsg;
                }));
               

            }
            catch (Exception ex)
            {

            }
        }



        private void Instance_AddMessage()
        {
            try
            {
                addMessageCount++;
                txtLeaveMessage.BeginInvoke(new Action(() =>
                {
                    txtLeaveMessage.Text = "完成：" + addMessageCount.ToString();
                }));
                txtCurBarcode.BeginInvoke(new Action(() =>
                {
                    txtCurBarcode.Text = "当前：" + StoParams.Instance.currentBarcode;
                }));

                if (m_arListDisplayBarcodes.Contains(StoParams.Instance.currentBarcode))
                {
                    m_arListDisplayBarcodes.Remove(StoParams.Instance.currentBarcode);
                }
                if (!m_arListManualLeaveBarcodes.Contains(StoParams.Instance.currentBarcode))
                {
                    m_arListManualLeaveBarcodes.Add(StoParams.Instance.currentBarcode);
                }
                StringBuilder sb = new StringBuilder();
                foreach (string strBarcode in m_arListDisplayBarcodes)
                {
                    sb.AppendLine(strBarcode);
                }
                StringBuilder sucessSB = new StringBuilder();
                foreach (string strBarcode in m_arListManualLeaveBarcodes)
                {
                    sucessSB.AppendLine(strBarcode);
                }
                if (m_arListManualLeaveBarcodes.Count > 50)
                {
                    m_arListManualLeaveBarcodes.Clear();
                }
                txtBarcodes.BeginInvoke(new Action(() =>
                {
                    txtBarcodes.Text = sb.ToString();
                }));
                rchRoadMap.BeginInvoke(new Action(() =>
                {
                    rchRoadMap.Text = "留言成功列表:\r\n" + sucessSB.ToString();
                }));

            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_DoneMemInfo()
        {
            try
            {
                lblSiteName.BeginInvoke(new Action(() =>
                {
                    if (StoParams.Instance.user_status == 2)
                    {
                        lblSiteName.Text = "请先注册网点信息";
                    }
                    else if (StoParams.Instance.user_status == 3)
                    {
                        lblSiteName.Text = StoParams.Instance.register_site + " 会员剩余查询次数0";
                    }
                    else
                    {
                        //lblSiteName.Text = ""+StoParams.Instance.register_site+"";
                    }
                }));


                lblLeftCount.BeginInvoke(new Action(() =>
                {
                    lblLeftCount.Text = StoParams.Instance.day_left.ToString();
                }));

            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_DoneArrOrDepAnay()
        {
            try
            {
                lblLeftCount.BeginInvoke(new Action(() =>
                {
                    lblLeftCount.Text = StoParams.Instance.day_left.ToString();

                }));

                lblDelayCount.BeginInvoke(new Action(() =>
                {
                    lblDelayCount.Text = "延误：" + DelayAnaHelperGen.Instance.m_ht_departure_BarCodes.Count.ToString();

                }));

            }
            catch (Exception ex)
            {
                MessageBox.Show("Instance_DoneArrOrDepAnay ex:" + ex.ToString());
            }
        }


        private void init()
        {
            UtilityHelp.Instance.initDtColumn(m_dt_ArrivalDelayed);
            UtilityHelp.Instance.initDtColumn(m_dt_DepartureDelayed);
            UtilityHelp.Instance.initDtColumn(m_dt_FruitDelayed);
            UtilityHelp.Instance.initDtFail(m_dt_LasnhouFail);
            UtilityHelp.Instance.initDtCopyColumn(m_dt_copy);
            UtilityHelp.Instance.initProvinceDelay();
            UtilityHelp.Instance.initRegSite();

            UtilityHelp.Instance.initWechatGroup();
            UtilityHelp.Instance.initBarcodeSite();
            UtilityHelp.Instance.initSiteToken();
            UtilityHelp.Instance.initGroupRoom();

            UtilityHelp.Instance.initInternalUserWord();

            UtilityHelp.Instance.initCloseRoom();
            if (StoParams.Instance.superWechatFlag.ToString().Contains("client"))
            {
                UtilityHelp.Instance.initAllOutboundType();
                UtilityHelp.Instance.initCustomerGroupEmployee();
            }
            
            UtilityHelp.Instance.initSiteWorkOrder();

            UtilityHelp.Instance.initSiteCustomer();
            UtilityHelp.Instance.initGroupPos();
            UtilityHelp.Instance.initContact();
            UtilityHelp.Instance.initPriorStieAndTime();
            UtilityHelp.Instance.initCheckZYStatus();
            UtilityHelp.Instance.initConfigSiteTime();
            UtilityHelp.Instance.initTemplete();
            UtilityHelp.Instance.initDelaySetting();
            UtilityHelp.Instance.initLanshouToken();
            UtilityHelp.Instance.initLanshouWechatDir();
            UtilityHelp.Instance.initUniqueSiteWechat();
            UtilityHelp.Instance.initLanshouScanUrl();
            UtilityHelp.Instance.initAllRooms();
            UtilityHelp.Instance.initAllRoomsEmplpee();
            
            UtilityHelp.Instance.initAllowLanshouRooms();
            UtilityHelp.Instance.initForbiddenLanshouRooms();
            UtilityHelp.Instance.initAllSites();
            InterceptMessageHelper.Instance.initNoRoadMap();
            UtilityHelp.Instance.initAllFilterWechatRooms();
            UtilityHelp.Instance.initAllInternalUser();
            UtilityHelp.Instance.initAllCodingWechatRooms();
            UtilityHelp.Instance.initAllDrawWechatRooms();
            UtilityHelp.Instance.initAllCustomerWxid();
            UtilityHelp.Instance.initAllLanshouWechatRooms();
            UtilityHelp.Instance.initAllGendanWechatRooms();
            UtilityHelp.Instance.initAllCommandGendan();

            UtilityHelp.Instance.initAllCommandCheck();
            UtilityHelp.Instance.initAllCommandQuestion();

            UtilityHelp.Instance.initAllCommandDraw();
            UtilityHelp.Instance.initAllCommandCoding();
            UtilityHelp.Instance.initAllCommandChangeCoding();
            UtilityHelp.Instance.initAllVipRooms();

            UtilityHelp.Instance.initLanshouSiteUrl();

        }



        private void Instance_Arrival_DoneAnay()
        {
            try
            {


            }
            catch (Exception ex)
            {

            }
        }

        private void Instance_Departure_DoneAnay()
        {
            try
            {
                
                if (dgvDelays.InvokeRequired)
                {
                    RefreshDgv c = new RefreshDgv(Instance_Departure_DoneAnay);
                    if (this.IsHandleCreated)
                    {
                        this.Invoke(c);
                    }
                }
                else
                {
                    lock (StoParams.Instance.obj_dep)
                    {
                        //Instance_DelayEvent();
                        Hashtable ht = JTDelayHelperNew.Instance.m_ht_departure_BarCodes;
                        if (ht.Count > 0)
                        {
                            m_htDepRoadMap = ht;
                            string strDelayed = "";
                            foreach (string strBarcode in JTDelayHelperNew.Instance.m_arlist_Delayed_BarCodes)
                            {
                                if (!m_ht_dep_filter.ContainsKey(strBarcode))
                                {
                                    if (ht.ContainsKey(strBarcode))
                                    {
                                        ResultBean resultBean = ht[strBarcode] as ResultBean;
                                        DataRow drNew = m_dt_DepartureDelayed.NewRow();
                                        drNew[0] = resultBean.lanshouSite;
                                        drNew[1] = resultBean.wayBillNo;
                                        drNew[2] = resultBean.dutySite;
                                        drNew[3] = resultBean.errorMsg;
                                        drNew[4] = resultBean.errorType;
                                        drNew[5] = resultBean.taskNo;
                                        drNew[6] = resultBean.planArrivalTime;

                                        drNew[7] = resultBean.planDepTime;
                                        drNew[8] = resultBean.actDepTime;


                                        drNew[9] = resultBean.transferDelay;

                                        drNew[10] = resultBean.jtyf;
                                        drNew[11] = resultBean.operatorTime;
                                        drNew[12] = resultBean.exceptionReportTime;

                                        drNew[13] = resultBean.lanshouTime;
                                        drNew[14] = resultBean.inWareHouseTime;
                                        drNew[15] = resultBean.finishTime;


                                        drNew[16] = resultBean.assignSite;
                                        drNew[17] = resultBean.lastScanTime;
                                        drNew[18] = resultBean.lastScanType;

                                        drNew[19] = resultBean.delayDays;

                                        m_dt_DepartureDelayed.Rows.Add(drNew);
                                        strDelayed = strDelayed + strBarcode + "\r\n";
                                        m_ht_dep_filter[strBarcode] = "";
                                    }
                                }

                            }

                            dgvDelays.BeginInvoke(new Action(() =>
                            {
                                mbs_departure = new BindingSource();
                                mbs_departure.DataSource = m_dt_DepartureDelayed;
                                dgvDelays.DataSource = mbs_departure;
                                for (int i = 0; i < m_dt_DepartureDelayed.Columns.Count; i++)
                                {
                                    //this.dgvDelays.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                    this.dgvDelays.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                                    if (i == 0)
                                    {
                                        this.dgvDelays.Columns[i].Width = 100;
                                        this.dgvDelays.Columns[i].ReadOnly = true;
                                        //this.dgvDelays.Columns[i].Width = 20;
                                    }
                                    if (i == 1)
                                    {
                                        this.dgvDelays.Columns[i].Width = 120;
                                        this.dgvDelays.Columns[i].ReadOnly = true;
                                        //this.dgvDelays.Columns[i].Width = 20;
                                    }
                                    if (i == 2)
                                    {
                                        //this.dgvDelays.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                        this.dgvDelays.Columns[i].Width = 120;
                                    }
                                    if (i == 3)
                                    {
                                        //this.dgvDelays.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                        this.dgvDelays.Columns[i].Width = 120;
                                    }

                                    if (i == 4)
                                    {
                                        //this.dgvDelays.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                        this.dgvDelays.Columns[i].Width = 120;
                                    }
                                    if (i == 5)
                                    {
                                        this.dgvDelays.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                        //this.dgvDelays.Columns[i].Width = 120;
                                    }
                                    if (i == 6)
                                    {
                                        this.dgvDelays.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                        //this.dgvDelays.Columns[i].Width = 120;
                                    }
                                    if (i == 7)
                                    {
                                        this.dgvDelays.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                        //this.dgvDelays.Columns[i].Width = 120;
                                    }
                                    if (i == 8)
                                    {
                                        this.dgvDelays.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                        //this.dgvDelays.Columns[i].Width = 120;
                                    }

                                }
                            }));


                        }
                    }
                }


            }
            catch (Exception ex)
            {
                //MessageBox.Show("Instance_Departure_DoneAnay " + ex.ToString());
            }
        }


        private void Instance_Fruit_DoneAnay()
        {
            try
            {




            }
            catch (Exception ex)
            {

            }
        }

        private void btnComput_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_dt_ArrivalDelayed.Rows.Count > 0)
                {
                    string strDir = this.getExportPath();
                    strDir = strDir + "\\" + "进港延误汇总_" + System.DateTime.Now.ToShortDateString() + ".xls";
                    string[] header = { "揽收网点", "运单号", "当前站点", "延误原因", "类型", "主线任务号", "延误天数", "揽收时间", "入库时间", "签收时间" };
                    if (UtilityExcel.Instance.ExportExcel(m_dt_ArrivalDelayed, header, strDir))
                    {
                        MessageBox.Show("结果导出成功");
                    }
                    else
                    {
                        MessageBox.Show("结果导出失败");
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }

        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (StoParams.Instance.day_left == 0)
                {
                    lblImportResult.Text = "导入条数：0";
                    MessageBox.Show("查询额度" + StoParams.Instance.day_total.ToString() + "已用完");
                    return;
                }
                int totalCount = 0;
                m_arListArrivalBarcodes.Clear();
                OpenFileDialog ofdg = new OpenFileDialog();
                if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string file = ofdg.FileName;//得到选择的文件的完整路径
                    m_arListArrivalBarcodes = UtilityHelp.Instance.getBarCodeFromFile(file, out totalCount);
                    if (m_arListArrivalBarcodes.Count == 0)
                    {
                        MessageBox.Show("没有取到运单号");
                        return;
                    }
                    mbs_arrival = null;
                    mbs_arrival = new BindingSource();

                    m_ht_arr_filter.Clear();
                    m_htRoadMap.Clear();
                    m_dt_ArrivalDelayed.Rows.Clear();
                    if (m_arListArrivalBarcodes.Count > StoParams.Instance.day_left)
                    {
                        ArrayList arListNew = new ArrayList();

                        for (int i = 0; i < StoParams.Instance.day_left; i++)
                        {
                            arListNew.Add(m_arListArrivalBarcodes[i]);
                        }
                        m_arListArrivalBarcodes.Clear();
                        m_arListArrivalBarcodes.AddRange(arListNew);
                    }
                    lblImportResult.Text = "导入条数：" + m_arListArrivalBarcodes.Count.ToString();
                    DelayAnaHelperGen.Instance.BeginAnalyThread(m_arListArrivalBarcodes, "arrival");

                }

            }
            catch (Exception ex)
            {

            }
        }

        public void SetTextMessage(int ipos, int total, string strLeftTime, string strProcessType = "检测")
        {

            if (this.InvokeRequired)
            {
                SetPos setpos = new SetPos(SetTextMessage);
                this.Invoke(setpos, new object[] { ipos, total, strLeftTime, strProcessType });

            }
            else
            {
                if (strLeftTime == "stop")
                {
                    probarDep.Visible = false;
                    label3.Visible = true;
                    label3.Text = "文件" + strProcessType + "未完成!";
                    return;
                }
                probarDep.Visible = true;

                this.lblLeft.Text = strLeftTime;

                this.probarDep.Maximum = total;

                this.probarDep.Value = Convert.ToInt32(ipos);
                if (ipos == total)
                {
                    //btnAdd.Enabled = true;
                    //probarDep.Visible = false;
                    //label3.Visible = true;
                    //label3.Text = strProcessType + "文件完成，请检测错误文件日志";
                }


            }

        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            this.rchRoadMap.Text = "";
        }

        private void dgvDelays_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                /*string barcode = this.dgvDelays.SelectedCells[0].Value.ToString();
                if (barcode.Length < 10)
                {
                    return;
                }
                if (m_htRoadMap.ContainsKey(barcode))
                {
                    RoadInfo roadMap = m_htRoadMap[barcode] as RoadInfo;
                    string runTime = roadMap.runTime;
                    string lastStaus = roadMap.lastScanStatus;
                    this.lblWaybill.Text = barcode;
                    this.lblTimeEff.Text = runTime;
                    this.lblStatus.Text = lastStaus;
                    ArrayList arListMems = roadMap.arListMems;
                    this.rchRoadMap.Text = "";
                    string strMsg = "";
                    foreach (MemInfo mem in arListMems)
                    {
                        strMsg = strMsg + mem.scanType + " " + mem.memMsg + "\r\n" + mem.scanTime + "\r\n" + "\r\n";
                    }
                    this.rchRoadMap.Text = strMsg;

                }*/
            }
            catch (Exception ex)
            {

            }
        }

        private void btnImportDep_Click(object sender, EventArgs e)
        {
            try
            {


                if (MemberInfo.Instance.token == "")
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }
                //临时
                if (!StoParams.Instance.isRegByMachine)
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }
                if(LoadBasicHelper.Instance.m_ht_main_effi.Count==0)
                {
                    MessageBox.Show("请导入干线路线");
                    return;
                }

                if (LoadBasicHelper.Instance.m_ht_sh_effi.Count == 0)
                {
                    MessageBox.Show("请导入散货时效");
                    return;
                }

                if (this.tabControl1.SelectedTab.Name != "tbDelay")
                {
                    this.tabControl1.SelectedIndex = 2;
                }
                    
                if (this.tabControl1.SelectedTab.Name == "tbAddComments")
                {
                    /*DialogResult MsgBoxResult;
                    MsgBoxResult = MessageBox.Show("当前登录的网点是："+ StoParams.Instance.register_site +" 登录用户:"+ StoParams.Instance.register_user + " 导入后会全部以该用户留言，请核对留言模板，并确定要这么做吗？",//对话框的显示内容
                    "确定留言",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Exclamation,
                    MessageBoxDefaultButton.Button2);

                    if (MsgBoxResult != DialogResult.Yes)//如果对话框的返回值是YES（按"Y"按钮）
                    {
                        return;
                    }*/

                    //handleLeaveMessage();
                }
                else if (this.tabControl1.SelectedTab.Name == "tbDelay")
                {
                    if (txtOutput.Text == "")
                    {
                        MessageBox.Show("请先设置延误单号输出路径");
                        return;
                    }
                    isUsing4Delay = true;
                    StoParams.Instance.outputDir = txtOutput.Text;
                    rchRoadMap.Text = "请等待几分钟，下载已申报的数据...";
                    handleDelay();
                }


            }
            catch (Exception ex)
            {

            }
        }

        private void handleDelay()
        {
            m_arListDepartureBarcodes.Clear();
            OpenFileDialog ofdg = new OpenFileDialog();
            if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                string file = ofdg.FileName;//得到选择的文件的完整路径
                totalCount = 0;
                m_arListDepartureBarcodes = UtilityHelp.Instance.getBarCodeFromFile(file, out totalCount);
                if (m_arListDepartureBarcodes.Count == 0)
                {
                    MessageBox.Show("没有取到运单号");
                    return;
                }
                mbs_departure = null;
                mbs_departure = new BindingSource();
                m_htDepRoadMap.Clear();
                m_ht_dep_filter.Clear();
                m_dt_DepartureDelayed.Rows.Clear();
                m_htCopyMap.Clear();
                int curFileCount = 0;
                StoParams.Instance.curParces = 0;
                this.handleDtCopyDgv(curFileCount);
                lblImportResult.Text = "导入条数：" + totalCount.ToString();
                txbImport.Text = "导入条数：" + totalCount.ToString();
                txtCurrentStatus.Text = "查询中";
                anylizeWaybillCount = 0;
                JTDelayHelperNew.Instance.BeginAnalyThread(m_arListDepartureBarcodes, "departure");

            }
        }

        private void handleLeaveMessage()
        {
            m_arListDepartureBarcodes.Clear();
            OpenFileDialog ofdg = new OpenFileDialog();
            if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                string file = ofdg.FileName;//得到选择的文件的完整路径
                int totalCount = 0;
                m_arListDepartureBarcodes = UtilityHelp.Instance.getBarCodeFromFile(file, out totalCount);
                if (m_arListDepartureBarcodes.Count == 0)
                {
                    MessageBox.Show("没有取到运单号");
                    return;
                }
                mbs_departure = null;
                mbs_departure = new BindingSource();
                m_htDepRoadMap.Clear();
                m_ht_dep_filter.Clear();
                m_dt_DepartureDelayed.Rows.Clear();
                m_htCopyMap.Clear();
                int curFileCount = 0;
                if (m_arListDepartureBarcodes.Count > StoParams.Instance.day_left)
                {



                    /*ArrayList arListNew = new ArrayList();

                    for (int i=0;i< StoParams.Instance.day_left;i++)
                    {
                        arListNew.Add(m_arListDepartureBarcodes[i]);
                    }
                    m_arListDepartureBarcodes.Clear();
                    m_arListDepartureBarcodes.AddRange(arListNew);*/
                }
                this.handleDtCopyDgv(curFileCount);
                lblImportResult.Text = "导入条数：" + totalCount.ToString();
                txbImport.Text = "导入条数：" + totalCount.ToString();

                if (totalCount > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    m_arListDisplayBarcodes.Clear();
                    foreach (ArrayList arListTmp in m_arListDepartureBarcodes)
                    {
                        foreach (string strBarcode in arListTmp)
                        {
                            sb.AppendLine(strBarcode);
                            m_arListDisplayBarcodes.Add(strBarcode);
                        }
                    }
                    //ArrayList arListBarcodes = (ArrayList)m_arListDepartureBarcodes[0];                       

                    this.txtBarcodes.Text = sb.ToString();
                }
                if (MemberInfo.Instance.templeteAssign.Trim().Length < 5 ||
                    MemberInfo.Instance.templeteTransfer.Trim().Length < 5 ||
                    MemberInfo.Instance.templeteQS.Trim().Length < 5 ||
                    MemberInfo.Instance.templeteReturn.Trim().Length < 5 ||
                    MemberInfo.Instance.templeteCuijian.Trim().Length < 5)
                {
                    MessageBox.Show("留言模板未设置");
                    return;
                }
                addMessageCount = 0;
                LeaveMessageHelperGen.Instance.BeginAnalyThread(m_arListDepartureBarcodes, "departure");

            }
        }

        private void handleDtCopyDgv(int curFileCount)
        {
            try
            {

            }
            catch (Exception ex)
            {
                MessageBox.Show("handleDtCopyDgv ex " + ex.ToString());
            }

        }

        private void menuDepSetting_Click(object sender, EventArgs e)
        {
            FrmDepSetting frmSetting = new FrmDepSetting();
            frmSetting.Show();
        }

        private void dgvDep_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string barcode = this.dgvDep.SelectedCells[0].Value.ToString();
                if (barcode.Length < 10)
                {
                    return;
                }
                if (m_htDepRoadMap.ContainsKey(barcode))
                {
                    RoadInfo roadMap = m_htDepRoadMap[barcode] as RoadInfo;
                    string runTime = roadMap.runTime;
                    string lastStaus = roadMap.lastScanStatus;
                    //this.lblWaybill.Text = barcode;
                    this.lblTimeEff.Text = runTime;
                    this.lblStatus.Text = lastStaus;
                    ArrayList arListMems = roadMap.arListMems;
                    this.rchRoadMap.Text = "";
                    string strMsg = "";
                    foreach (MemInfo mem in arListMems)
                    {
                        strMsg = strMsg + mem.scanType + " " + mem.memMsg + "\r\n" + mem.scanTime + "\r\n" + "\r\n";
                    }
                    this.rchRoadMap.Text = strMsg;

                }
            }
            catch (Exception ex)
            {

            }

        }



        private void menuRegister_Click(object sender, EventArgs e)
        {

            frmRigister.ShowDialog();

        }

        private void menuSiteSttting_Click(object sender, EventArgs e)
        {
            FrmSiteName frmSite = new FrmSiteName();
            frmSite.ShowDialog();
            this.lblSiteName.Text = StoParams.Instance.register_site + "";
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            if (StoParams.Instance.isServerStart)
            {
                this.lblWeChat.Text = "服务端已启动";
            }
            if (cbEffi.Checked)
            {
                LoadBasicHelper.Instance.isEffiCheck = true;
            }
            FrmLogin frmLogin = new view.FrmLogin();
            frmLogin.ShowDialog();
            if (MemberInfo.Instance.jmsUser == "")
            {
                this.Close();
            }
            string dir = Directory.GetCurrentDirectory();
            string[] arr = dir.Split('\\');
            this.Text = this.Text + "-" + arr[arr.Length - 1];

            //this.lblSiteName.Text = StoParams.Instance.register_site+"";
            if (StoParams.Instance.user_status == 2 || StoParams.Instance.register_site == null)
            {
                this.lblSiteName.Text = "请先注册网点信息";

            }
            //this.Text = this.Text ;


            Control.CheckForIllegalCrossThreadCalls = false;
            this.cbAssignDelay.Checked = StoParams.Instance.isAssignCheck;
            //JTTimeEffi.Instance.initTimeMap();
            //this.txtWaybill.Text = MemberInfo.Instance.templeteTransfer;

            this.txtTransferTmp.Text = MemberInfo.Instance.templeteTransfer;
            this.txtLVTransfer.Text = MemberInfo.Instance.templeteTransfer;
            this.txtAssignTmp.Text = MemberInfo.Instance.templeteAssign;
            this.txtLVAssign.Text = MemberInfo.Instance.templeteAssign;
            this.txtQSTmp.Text = MemberInfo.Instance.templeteQS;
            this.txtLVQS.Text = MemberInfo.Instance.templeteQS;

            this.txtDelayHeader.SelectionAlignment = HorizontalAlignment.Center;
            string readSHEffi = this.readSHData();
            string readMainEffi = this.readMainLineData();
            if (readSHEffi != "" && readMainEffi != "")
            {
                this.txtDelayHeader.Text = "  " + readSHEffi + "\r\n" + readMainEffi;
            }
            this.txtDelayHeader.Text = this.txtDelayHeader.Text + " " + " 导入散货时效需要线下载所有散货时效，再导入散货时效excel";
            this.dgvDelays.RowHeadersWidth = 60;
            
            if (!UtilityHelp.Instance.isContainCC())
            {
                //menuDelayTypeFilter.Visible = false;
                this.tabControl1.TabPages.RemoveAt(2);
                //btnImportDep.Enabled = false;
            }

            //DbManager.Instance.Init();
            FrameDecoderManager.Instance.initLog();

            //MessageHandleManager.Instance.initLog();

            //TransactionDatabase.Instance.Init(DbManager.Instance.CameraDbFactory);
            //DbMessageHandle.Instance.BeginAnalyThread();
            if (StoParams.Instance.isDbConnect)
            {
                //lbDBStatus.Text = "已连接";
            }

            //ImageDelHelper.Instance.BeginImgThread(this.txtOutput.Text);
            handleFileWatch();
            this.tabControl1.SelectedIndex = 2;

            /*ParcelBean parcle = new ParcelBean();
            parcle.wayBill = "JT5171274264627";
            parcle.weight = "0.05";
            ArrayList ar = new ArrayList();
            ar.Add(parcle);
            string msg = "";
            bool res = LanshouHelperGen.Instance.lanshouParcel(ar, out msg);*/


            //this.dgvDelays.RowHeadersWidthSizeMode= DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
        }

        [PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
        private void handleFileWatch()
        {
            try
            {
                FileSystemWatcher watcher = new FileSystemWatcher();
                watcher.Path = StoParams.Instance.wechatGroupFileDir;
                watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
               | NotifyFilters.FileName | NotifyFilters.DirectoryName;
                watcher.Filter = "*.*";
                watcher.Created += Watcher_Created;

                watcher.EnableRaisingEvents = true;
            }
            catch (Exception ex)
            {

            }

        }

        private void Watcher_Created(object sender, FileSystemEventArgs e)
        {
            try
            {

                string fullNamePath = e.FullPath;
                logHelp.LogHelper.Instance.writeLog("收到文件：" + fullNamePath);
                System.Threading.Thread.Sleep(2000);
                if (fullNamePath.Contains(".xls"))
                {
                    fullNamePath = fullNamePath.Substring(0, fullNamePath.IndexOf(".xls") + 4);
                }
                else
                {
                    return;
                }
                logHelp.LogHelper.Instance.writeLog("简化后文件名：" + fullNamePath);
                ArrayList arList = UtilityExcel.Instance.GetWechatDirExcelData(fullNamePath);
                if (arList.Count > 0)
                {
                    ArrayList arListSplitBeanList = UtilityHelp.Instance.getLanshouArList(arList);
                    FrameDecoderManager.Instance.doTaskLanshou(arListSplitBeanList);
                }

            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("Watcher_Created error：" + ex.ToString());
            }
        }

        private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            try
            {
                InterceptMessageHelper.Instance.logNoRoadMapBarcodes();
                ImageDelHelper.Instance.stopThread();

                DelayAnaHelperGen.Instance.stopThread();
                FrameDecoderManager.Instance.stopThread();
                //MessageHandleManager.Instance.stopThread();

            }
            catch (Exception ex)
            {

            }

        }

        private void dgvDelays_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            try
            {
                //添加行号 
                /*SolidBrush v_SolidBrush = new SolidBrush(this.dgvDelays.RowHeadersDefaultCellStyle.ForeColor);
                int v_LineNo = 0;
                v_LineNo = e.RowIndex + 1;

                string v_Line = v_LineNo.ToString();

                e.Graphics.DrawString(v_Line, e.InheritedRowStyle.Font, v_SolidBrush, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);*/

            }
            catch (Exception ex)
            {
                MessageBox.Show("添加行号时发生错误，错误信息：" + ex.Message, "操作失败");
            }
        }

        private void dgvDep_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            try
            {
                //添加行号 
                SolidBrush v_SolidBrush = new SolidBrush(this.dgvDep.RowHeadersDefaultCellStyle.ForeColor);
                int v_LineNo = 0;
                v_LineNo = e.RowIndex + 1;

                string v_Line = v_LineNo.ToString();

                e.Graphics.DrawString(v_Line, e.InheritedRowStyle.Font, v_SolidBrush, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);

            }
            catch (Exception ex)
            {
                MessageBox.Show("添加行号时发生错误，错误信息：" + ex.Message, "操作失败");
            }
        }


        private void dgvFruit_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                /*string barcode = this.dgvFruit.SelectedCells[0].Value.ToString();
                if (barcode.Length < 10)
                {
                    return;
                }
                if (m_htFruitRoadMap.ContainsKey(barcode))
                {
                    RoadInfo roadMap = m_htFruitRoadMap[barcode] as RoadInfo;
                    string runTime = roadMap.runTime;
                    string lastStaus = roadMap.lastScanStatus;
                    this.lblWaybill.Text = barcode;
                    this.lblTimeEff.Text = runTime;
                    this.lblStatus.Text = lastStaus;
                    ArrayList arListMems = roadMap.arListMems;
                    this.rchRoadMap.Text = "";
                    string strMsg = "";
                    foreach (MemInfo mem in arListMems)
                    {
                        strMsg = strMsg + mem.scanType + " " + mem.memMsg + "\r\n" + mem.scanTime + "\r\n" + "\r\n";
                    }
                    this.rchRoadMap.Text = strMsg;

                }*/
            }
            catch (Exception ex)
            {

            }
        }

        private string getExportPath()
        {
            string strRes = "";
            System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
       
            

            dialog.Description = "请选择导出结果文件夹";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (string.IsNullOrEmpty(dialog.SelectedPath))
                {
                    MessageBox.Show(this, "文件夹路径不能为空", "提示");
                    return "";
                }

                strRes = dialog.SelectedPath;
                this.txtOutput.Text = strRes;
                StoParams.Instance.outputDir= strRes;
            }
            return strRes;
        }

        private void btnExportDep_Click(object sender, EventArgs e)
        {
            try
            {
                string strDir = this.getExportPath();
                //string strDir ="D:\\";
                if (m_dt_DepartureDelayed.Rows.Count > 0)
                {
                    strDir = strDir + "\\" + "出港延误汇总_" + (exportTime++).ToString() + "_" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
                    string[] header = { "揽收网点", "运单号", "当前站点", "延误原因", "类型", "主线任务号", "计划到件时间", "计划发出时间", "实际发出时间", "班车延误", "既囤又发", "操作时长", "异常报备信息", "揽收时间", "入库时间", "签收时间", "签收网点", "最后扫描时间", "最后扫描类型", "延误天数" };
                    if (UtilityExcel.Instance.ExportExcel(m_dt_DepartureDelayed, header, strDir))
                    {
                        MessageBox.Show("结果导出成功");
                    }
                    else
                    {
                        MessageBox.Show("结果导出失败");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("结果导出失败:"+ex.ToString());
                return;
                //throw;
            }
        }

        private void btnQueryArrival_Click(object sender, EventArgs e)
        {

        }

        private void btnQueryDep_Click(object sender, EventArgs e)
        {
            string barcode = this.tbWayBillDep.Text;
            if (barcode.Length > 10)
            {
                queryOneWayBill(barcode);
            }
            else
            {
                MessageBox.Show("条码长度不符合");
            }
        }

        private void btnQueryFruit_Click(object sender, EventArgs e)
        {

        }

        private void queryOneWayBill(string barcode)
        {
            Hashtable htWaybill = new Hashtable();
            DelayAnaHelperGen.Instance.queryWayBill(htWaybill, barcode);
            if (htWaybill.Count > 0)
            {
                if (htWaybill.ContainsKey(barcode))
                {
                    RoadInfo roadMap = htWaybill[barcode] as RoadInfo;
                    string runTime = roadMap.runTime;
                    string lastStaus = roadMap.lastScanStatus;
                    //this.lblWaybill.Text = barcode;
                    this.lblTimeEff.Text = runTime;
                    this.lblStatus.Text = lastStaus;
                    ArrayList arListMems = roadMap.arListMems;
                    this.rchRoadMap.Text = "";
                    string strMsg = "";
                    foreach (MemInfo mem in arListMems)
                    {
                        strMsg = strMsg + mem.scanType + " " + mem.memMsg + "\r\n" + mem.scanTime + "\r\n" + "\r\n";
                    }
                    this.rchRoadMap.Text = strMsg;

                }
            }

        }

        private void menuCustom_Click(object sender, EventArgs e)
        {

        }

        private void menuArr_Click(object sender, EventArgs e)
        {

        }

        private void btnHelp_Click(object sender, EventArgs e)
        {

        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            try
            {
                LeaveMessageHelperGen.Instance.stopThread();
            }
            catch (Exception ex)
            {

            }
        }

        private void btnArrStop_Click(object sender, EventArgs e)
        {
            try
            {

                DelayAnaHelperGen.Instance.stopThread();
            }
            catch (Exception ex)
            {

            }
        }

        private void btnStopFruit_Click(object sender, EventArgs e)
        {
            try
            {
                DelayAnaHelperGen.Instance.stopThread();
            }
            catch (Exception ex)
            {

            }
        }

        private void btnExportFruitResult_Click(object sender, EventArgs e)
        {
            try
            {
                string strDir = this.getExportPath();
                if (m_dt_FruitDelayed.Rows.Count > 0)
                {
                    strDir = strDir + "\\" + "出港延误汇总_" + System.DateTime.Now.ToShortDateString() + ".xls";
                    string[] header = { "揽收网点", "运单号", "当前站点", "延误原因", "类型", "主线任务号", "延误天数", "揽收时间", "入库时间", "签收时间" };
                    if (UtilityExcel.Instance.ExportExcel(m_dt_FruitDelayed, header, strDir))
                    {
                        MessageBox.Show("结果导出成功");
                    }
                    else
                    {
                        MessageBox.Show("结果导出失败");
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void importDemo_Click(object sender, EventArgs e)
        {

        }
        private void CopyFile(string srcFile, string destDir)
        {
            try
            {
                DirectoryInfo destDirectory = new DirectoryInfo(destDir);
                string fileName = Path.GetFileName(srcFile);
                if (!File.Exists(srcFile))
                {
                    return;
                }

                if (!destDirectory.Exists)
                {
                    destDirectory.Create();
                }

                File.Copy(srcFile, destDirectory.FullName + @"\" + fileName, true);
                MessageBox.Show("模板导出成功");
            }
            catch (Exception ex)
            {

            }


        }

        private void cbAssignDelay_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                StoParams.Instance.isAssignCheck = this.cbAssignDelay.Checked;
                string strCheckStatus = "false";
                if (StoParams.Instance.isAssignCheck)
                {
                    strCheckStatus = "true";
                }
                Utility.writeTbFile(StoParams.Instance.checkTxtPath, strCheckStatus);
            }
            catch (Exception ex)
            {

            }
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                ArrayList arList = new ArrayList();
                arList.Add("4839423049320");
                arList.Add("4839423049321");
                arList.Add("4839423049322");
                arList.Add("4839423049323");
                arList.Add("4839423049324");
                Clipboard.SetDataObject("773041731692253\r\n773041644998432\r\n773041648455923");

                int rowCount = this.rchRoadMap.Lines.Count();
                if (rowCount < 2)
                {
                    MessageBox.Show("文本内容不能为空");
                    return;
                }


            }
            catch (Exception ex)
            {

            }
        }

        private void rchRoadMap_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                ArrayList arListAllLines = new ArrayList();
                arListAllLines.Clear();
                // arListAllLines.AddRange(this.rchRoadMap.Lines);
                //DelayAnaHelperGen.Instance.BeginAnalyThread(arListAllLines, "departure");
                this.rchRoadMap.Text = "";
                this.rchRoadMap.Clear();
                countTime++;
                if (countTime % 5 == 0)
                {
                    System.GC.Collect();
                }




            }
        }



        private void dgvCopy_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {

            }
            catch (Exception ex)
            {

            }

        }

        private void btnImportRoadMap_Click(object sender, EventArgs e)
        {
            try
            {
                m_arListDepartureBarcodes.Clear();
                OpenFileDialog ofdg = new OpenFileDialog();
                int barCodeCount = 0;
                if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string file = ofdg.FileName;//得到选择的文件的完整路径
                    m_arListDepartureBarcodes = UtilityHelp.Instance.getRoadMapListFromFile(file, out barCodeCount);
                    if (m_arListDepartureBarcodes.Count == 0)
                    {
                        MessageBox.Show("没有取到运单号");
                        return;
                    }
                    mbs_departure = null;
                    mbs_departure = new BindingSource();
                    m_htDepRoadMap.Clear();
                    m_ht_dep_filter.Clear();
                    m_dt_DepartureDelayed.Rows.Clear();
                    m_htCopyMap.Clear();
                    int curFileCount = 0;
                    if (m_arListDepartureBarcodes.Count > StoParams.Instance.day_left)
                    {
                        ArrayList arListCopy = new ArrayList();

                        /*for (int i = 0; i < m_arListDepartureBarcodes.Count; i++)
                        {
                            arListCopy.Add(m_arListDepartureBarcodes[i]);
                            if (i % 200 == 0 && i > 0)
                            {
                                curFileCount++;
                                m_htCopyMap[curFileCount.ToString()] = arListCopy.Clone();
                                arListCopy.Clear();
                            }
                        }
                        m_htCopyMap[curFileCount.ToString()] = arListCopy.Clone();*/

                        /*ArrayList arListNew = new ArrayList();
                        
                        for (int i=0;i< StoParams.Instance.day_left;i++)
                        {
                            arListNew.Add(m_arListDepartureBarcodes[i]);
                        }
                        m_arListDepartureBarcodes.Clear();
                        m_arListDepartureBarcodes.AddRange(arListNew);*/
                    }
                    //this.handleDtCopyDgv(curFileCount);
                    lblImportResult.Text = "导入运单条数：" + barCodeCount.ToString();
                    DelayAnaHelperGen.Instance.BeginAnalyThread(m_arListDepartureBarcodes, "departure");



                }
            }
            catch (Exception ex)
            {

            }
        }

        private void dgvCopy_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {

            }
            catch (Exception ex)
            {

            }
        }

        private void menuDir_Click(object sender, EventArgs e)
        {

        }

        private void menuFilePath_Click(object sender, EventArgs e)
        {

        }

        private void cbCYDelay_Click(object sender, EventArgs e)
        {
            MemberInfo.Instance.isCheckDeliverDelay = this.cbCYDelay.Checked;
        }

        private void machine_Click(object sender, EventArgs e)
        {
            FrmMachine frmachine = new view.FrmMachine();
            frmachine.ShowDialog();
            this.lblSiteName.Text = StoParams.Instance.register_site + "";
            if (StoParams.Instance.register_site != "")
            {
                Thread t = new Thread(loadCityEffi);
                t.Start();
            }
            if (!this.Text.Contains(StoParams.Instance.register_site))
            {
                this.Text = this.Text + "-" + StoParams.Instance.register_site + "";
            }
        }

        private void loadCityEffi()
        {
            UtilityExcel.Instance.GetExcelData("附件9紫金山时效标准统计(20211220版).xlsx");
        }

        private void templetSetting_Click(object sender, EventArgs e)
        {
            try
            {
                FrmSetting frmSetting = new FrmSetting();
                frmSetting.ShowDialog();
                //this.txtWaybill.Text = MemberInfo.Instance.templeteTransfer;
                this.txtTransferTmp.Text = MemberInfo.Instance.templeteTransfer;
                this.txtLVTransfer.Text = MemberInfo.Instance.templeteTransfer;
                this.txtAssignTmp.Text = MemberInfo.Instance.templeteAssign;
                this.txtLVAssign.Text = MemberInfo.Instance.templeteAssign;
                this.txtQSTmp.Text = MemberInfo.Instance.templeteQS;
                this.txtLVQS.Text = MemberInfo.Instance.templeteQS;
            }
            catch (Exception ex)
            {

            }
        }

        private void cbFastMode_CheckedChanged(object sender, EventArgs e)
        {
            bool isFast = this.cbFastMode.Checked;
            StoParams.Instance.isFastMode = isFast;
        }

        private void btnLoadBasicData_Click(object sender, EventArgs e)
        {
           
            string path = @"";
            OpenFileDialog ofdg = new OpenFileDialog();
            if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                path = ofdg.FileName;//得到选择的文件的完整路径
            }
            else
            {
                return;
            }

         
            StoParams.Instance.totalPages = 0;
            StoParams.Instance.curPage = 0;
            //string path = @"C:\Users\才子\Desktop\邻\0801\散货时效836f1d45-f4c4-4b57-bd22-e3126fa27c55 (1).xlsx";
            Worksheet sheet1 = UtilityExcel.Instance.GetWorksheet(path, 0);
            int rowCount = sheet1.Cells.Rows.Count;
            if(rowCount<100)
            {
                MessageBox.Show("散货时效加载异常");
                return;
            }

            ArrayList arListSh= LoadBasicHelper.Instance.loadExcelSHData(sheet1, rowCount);
            

             StringBuilder sb = new StringBuilder();
            ArrayList arListZcBeans = new ArrayList();

        
            MessageBox.Show("散货时效加载完成 , 导入线路:" + arListSh.Count.ToString());
            txtDelayHeader.Text = "散货时效加载完成 , 导入线路:" + arListSh.Count.ToString();

            //LoadBasicHelper.Instance.BeginLoadThread();
        }
        private string readSHData()
        {
            string strRes = "";
            try
            {
                FileInfo fi = new FileInfo(StoParams.Instance.SJPath);
                DateTime writeTime = fi.LastWriteTime;


                ArrayList arListSH = new ArrayList();
                foreach (string line in File.ReadLines(StoParams.Instance.SJPath, EncodingType.GetType(StoParams.Instance.SJPath)))
                {
                    if (line.Trim().Length > 10)
                    {
                        arListSH.Add(line);
                    }
                }
                bool isContainEffiDate = false;
                LoadBasicHelper.Instance.m_ht_sh_effi = UtilityHelp.Instance.getSHEffi(arListSH,out isContainEffiDate);
                if (LoadBasicHelper.Instance.m_ht_sh_effi.Count > 100)
                {
                    strRes = "散货时效上次下载时间:" + fi.LastWriteTime.ToShortDateString();
                }
                if(!isContainEffiDate)
                {
                    strRes = "请重新下载散货时效，否则一个也查不出延误";
                    MessageBox.Show("请重新下载散货时效，否则一个也查不出延误");
                }

            }
            catch (Exception ex)
            {
                //MessageBox.Show("请重新下载散货时效，否则一个也查不出延误");
            }
            return strRes;
        }
        private string readMainLineData()
        {
            string strRes = "";
            try
            {
                FileInfo fi = new FileInfo(StoParams.Instance.MainLinePath);
                DateTime writeTime = fi.LastWriteTime;


                ArrayList arListMain = new ArrayList();
                foreach (string line in File.ReadLines(StoParams.Instance.MainLinePath, EncodingType.GetType(StoParams.Instance.MainLinePath)))
                {
                    if (line.Trim().Length > 10)
                    {
                        arListMain.Add(line);
                    }
                }
                LoadBasicHelper.Instance.m_ht_main_line.Clear();
                //LoadBasicHelper.Instance.m_ht_main_effi = UtilityHelp.Instance.getSHEffi(arListMain);
                LoadBasicHelper.Instance.m_ht_main_effi = UtilityHelp.Instance.getMainLineEffi(arListMain, LoadBasicHelper.Instance.m_ht_main_line);
                if (LoadBasicHelper.Instance.m_ht_main_effi.Count > 10)
                {
                    strRes = "  干线时效上次下载时间:" + fi.LastWriteTime.ToShortDateString();
                    System.DateTime dtNow = System.DateTime.Now;
                    TimeSpan ts = dtNow - fi.LastWriteTime;
                    if (ts.TotalDays > 3)
                    {
                        strRes = strRes + " 建议重新下载路由时效数据,否则影响数据准确性";
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return strRes;
        }

        private void dgvDelays_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);

        }

        private void btnBroswer_Click(object sender, EventArgs e)
        {
            try
            {
                System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
                string strDefaultDir = txtOutput.Text.Trim();
                
                if (Directory.Exists(strDefaultDir + "\\"))
                {
                    dialog.SelectedPath = strDefaultDir;
                }
                dialog.Description = "请选择输出文件所在文件夹";
                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (string.IsNullOrEmpty(dialog.SelectedPath))
                    {
                        MessageBox.Show(this, "文件夹路径不能为空", "提示");
                        return;
                    }
                    this.txtOutput.Text = dialog.SelectedPath;
                    StoParams.Instance.outputDir= dialog.SelectedPath;
                    createFilePath(this.txtOutput.Text);
                }
            }
            catch (Exception ex)
            {

            }
        }

        private void createFilePath(string strFilePath)
        {
            try
            {
                string delFile = System.Environment.CurrentDirectory + "\\" + "Path.txt";
                if(File.Exists(delFile))
                {
                    File.Delete(delFile);
                    FileStream bFile = new FileStream(delFile, FileMode.Create);
                    StreamWriter swb = null;
                    if (swb == null)
                    {
                        swb = new StreamWriter(bFile);
                    }
                    swb.WriteLine(strFilePath);
                    swb.Close();
                }
                

            }
            catch (Exception ex)
            {

            }
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Directory.Exists(this.txtOutput.Text.Trim()))
                {
                    MessageBox.Show("输出文件路径不存在，请检查");
                    return;
                }
                System.Diagnostics.Process.Start(this.txtOutput.Text.Trim());
            }
            catch (Exception ex)
            {

            }
        }

        private void readPath()
        {
            try
            {
                string strFileName = System.Environment.CurrentDirectory + "\\" + "Path.txt";
                ArrayList arList = new ArrayList();
                int rowCount = 1;
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (rowCount == 1)
                    {
                        if (Directory.Exists(line))
                        {
                            this.txtOutput.Text = line;
                        }
                        else
                        {
                            this.txtOutput.Text = "D:\\";
                        }
                        StoParams.Instance.outputDir = this.txtOutput.Text;
                    }
                    rowCount++;

                }
                if (this.txtOutput.Text.Length > 5)
                {
                    StoParams.Instance.userGroupTxtPath = this.txtOutput.Text.Replace("image", "coordinate").Trim() + "\\" + "group.txt";
                }
            }
            catch (Exception ex)
            {

            }
        }

        private void btnOperationSetting_Click(object sender, EventArgs e)
        {

        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                this.lblTotal.Text = "0";
                this.lblQueryTotal.Text = "0";
                this.lblFinishPercent.Text = "0";
                this.lblAddCount.Text = "0";
                rchRoadMap.Text = "";
                SelectTimeBean selectBean = new SelectTimeBean();
                selectBean.startTime = this.dateTimePicker1.Value;
                selectBean.endTime = this.dateTimePicker2.Value;

                if (selectBean.startTime > System.DateTime.Now)
                {
                    MessageBox.Show("开始时间不能大于当前时间");
                    return;
                }

                if (LeaveMessageHelperAuto.Instance.isInLeaveProcess)
                {
                    MessageBox.Show("留言已开始，请勿重复点击");
                    return;
                }
                if (selectBean.startTime >= selectBean.endTime)
                {
                    MessageBox.Show("未设置查询时间");
                    return;
                }
                if (StoParams.Instance.register_wechat == "")
                {
                    MessageBox.Show("机器人授权里 未设置留言微信");
                    return;
                }
                TimeSpan ts = selectBean.endTime - selectBean.startTime;
                if (ts.TotalHours > 72)
                {
                    MessageBox.Show("时段不能超过72小时");
                    return;
                }

                if (MemberInfo.Instance.token == "")
                {
                    MessageBox.Show("未登录授权");
                    return;
                }
                rchRoadMap.Text = "请等待几分钟，下载已申报的数据...";
                LeaveMessageHelperAuto.Instance.BeginAnalyThread(selectBean, "");
            }
            catch (Exception ex)
            {

            }
        }





        private void dateTimePicker1_MouseDown(object sender, MouseEventArgs e)
        {
            dateTimePicker1.Value = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day, 0, 0, 0);
        }

        private void dateTimePicker2_MouseDown(object sender, MouseEventArgs e)
        {
            dateTimePicker2.Value = new DateTime(dateTimePicker2.Value.Year, dateTimePicker2.Value.Month, dateTimePicker2.Value.Day, 23, 59, 59);
        }

        private void btnStopAuto_Click(object sender, EventArgs e)
        {
            try
            {
                StoParams.Instance.isProcessStop = true;
                LeaveMessageHelperAuto.Instance.isInLeaveProcess = false;
            }
            catch (Exception ex)
            {

            }
        }

        private void btnContinue_Click(object sender, EventArgs e)
        {
            try
            {
                StoParams.Instance.isProcessStop = false;
            }
            catch (Exception ex)
            {

            }
        }

        private void btnIntercept_Click(object sender, EventArgs e)
        {

        }





        private void btnCJ_Click(object sender, EventArgs e)
        {
            if (MemberInfo.Instance.token == "")
            {
                MessageBox.Show("未登录授权");
                return;
            }
            if (txtCJWaybills.Text.Trim() == "")
            {
                MessageBox.Show("单号不能为空");
                return;
            }
            /*if (MemberInfo.Instance.token == "")
            {
                MessageBox.Show("未登录授权");
                return;
            }
            if (txtCJWaybills.Text.Trim() == "")
            {
                MessageBox.Show("单号不能为空");
                return;
            }
            if (MemberInfo.Instance.templeteCuijian == "")
            {
                MessageBox.Show("未设置催件留言模板");
                return;
            }

            this.tbWaybillNo.Text = txtCJWaybills.Text.Trim();
            ArrayList arListCJWaybills = new ArrayList();
            if (txtCJWaybills.Text.Trim().Contains(","))
            {
                tbWaybillNo.Text = txtCJWaybills.Text.Replace(",", "\n");
            }
            arListCJWaybills.AddRange(txtCJWaybills.Text.Trim().Split('\n'));

            rchRoadMap.Text = "开始催件...";
            CuiJianMessageHelper.Instance.BeginAnalyThread(arListCJWaybills, "");
            txtCJWaybills.Text = "";*/


            m_arListManualLeaveBarcodes.Clear();
            rchRoadMap.Text = "";
            /*if (MemberInfo.Instance.token == "")
            {
                MessageBox.Show("未登录授权");
                return;
            }
            if (txtCJWaybills.Text.Trim() == "")
            {
                MessageBox.Show("单号不能为空");
                return;
            }
            if (MemberInfo.Instance.templeteAssign == "" || MemberInfo.Instance.templeteTransfer == ""
                   || MemberInfo.Instance.templeteQS == "" || MemberInfo.Instance.templeteReturn == "")
            {
                MessageBox.Show("未设置留言模板");
                return;
            }*/

            if (MemberInfo.Instance.templeteAssign.Length > 30 || MemberInfo.Instance.templeteTransfer.Length > 30
                || MemberInfo.Instance.templeteReturn.Length > 30)
            {
                MessageBox.Show("留言模板过长，只需要留微信即可");
                return;
            }

            StoParams.Instance.totalParcels = 0;
            StoParams.Instance.curParces = 0;

            ArrayList arListLeaveMsgWaybills = new ArrayList();

            string allContent = txtCJWaybills.Text.Trim();
            int curLoop = 0;
            if (allContent.Length > 16000)
            {
                while (allContent.Length > 16000)
                {
                    curLoop++;
                    char[] jt = "JT".ToCharArray();
                    int spintIndex = allContent.IndexOfAny(jt, 16000);
                    //string sub = allContent.Substring(0, allContent.IndexOfAny(jt, spintIndex));
                    string sub = allContent.Substring(0, spintIndex);
                    ArrayList atlitTmp = UtilityHelp.Instance.getInputBarcodesAndAddr(sub,new TaskBean());
                    arListLeaveMsgWaybills.AddRange(atlitTmp);
                    allContent = allContent.Substring(spintIndex);


                }
                if(allContent.Length>13&& allContent.Length<1600)
                {                    
                    ArrayList atlitTmp = UtilityHelp.Instance.getInputBarcodesAndAddr(allContent, new TaskBean());
                    arListLeaveMsgWaybills.AddRange(atlitTmp);
     
                }

            }
            else
            {
                arListLeaveMsgWaybills = UtilityHelp.Instance.getInputBarcodesAndAddr(txtCJWaybills.Text.Trim(), new TaskBean());
            }

            //arListLeaveMsgWaybills = UtilityHelp.Instance.getInputBarcodesAndAddr(txtCJWaybills.Text.Trim());
            txtCJWaybills.Text = txtCJWaybills.Text.Replace("，", ",");
            if (txtCJWaybills.Text.Trim().Contains(","))
            {
                txtCJWaybills.Text = txtCJWaybills.Text.Replace(",", "\n");
            }
            //arListLeaveMsgWaybills.AddRange(txtCJWaybills.Text.Trim().Split('\n'));

            lblImportResult.Text = "输入条数：" + arListLeaveMsgWaybills.Count.ToString();
            txbImport.Text = "输入条数：" + arListLeaveMsgWaybills.Count.ToString();

            if (arListLeaveMsgWaybills.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                m_arListDisplayBarcodes.Clear();
                foreach (ParcelBean parcelBean in arListLeaveMsgWaybills)
                {
                    sb.AppendLine(parcelBean.wayBill);
                    m_arListDisplayBarcodes.Add(parcelBean.wayBill);
                }

                this.txtBarcodes.Text = sb.ToString();
            }



            rchRoadMap.Text = "开始留言...";
            LeaveMessageHelperGen.Instance.BeginAnalyThread(arListLeaveMsgWaybills, "manual");
            txtCJWaybills.Text = "";
        }

        private void btnLeaverMsgManual_Click(object sender, EventArgs e)
        {
            /*m_arListManualLeaveBarcodes.Clear();
            rchRoadMap.Text = "";
            if (MemberInfo.Instance.token == "")
            {
                MessageBox.Show("未登录授权");
                return;
            }
            if (tbLeaveWayBills.Text.Trim() == "")
            {
                MessageBox.Show("单号不能为空");
                return;
            }
            if (MemberInfo.Instance.templeteAssign == "" || MemberInfo.Instance.templeteTransfer == ""
                   || MemberInfo.Instance.templeteQS == "" || MemberInfo.Instance.templeteReturn == "")
            {
                MessageBox.Show("未设置留言模板");
                return;
            }
            ArrayList arListLeaveMsgWaybills = new ArrayList();
            tbLeaveWayBills.Text = tbLeaveWayBills.Text.Replace("，", ",");
            if (tbLeaveWayBills.Text.Trim().Contains(","))
            {
                tbLeaveWayBills.Text = tbLeaveWayBills.Text.Replace(",", "\n");
            }
            arListLeaveMsgWaybills.AddRange(tbLeaveWayBills.Text.Trim().Split('\n'));

            lblImportResult.Text = "输入条数：" + arListLeaveMsgWaybills.Count.ToString();
            txbImport.Text = "输入条数：" + arListLeaveMsgWaybills.Count.ToString();

            if (arListLeaveMsgWaybills.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                m_arListDisplayBarcodes.Clear();
                foreach (string strBarcode in arListLeaveMsgWaybills)
                {
                    sb.AppendLine(strBarcode);
                    m_arListDisplayBarcodes.Add(strBarcode);
                }                   

                this.txtBarcodes.Text = sb.ToString();
            }


           
            rchRoadMap.Text = "开始留言...";
            LeaveMessageHelperGen.Instance.BeginAnalyThread(arListLeaveMsgWaybills, "");
            tbLeaveWayBills.Text = "";*/

        }

        private void tabControl3_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void InterceptConfig_Click(object sender, EventArgs e)
        {

        }

        private void cbEffi_Click(object sender, EventArgs e)
        {
            if (this.cbEffi.Checked)
            {
                LoadBasicHelper.Instance.isEffiCheck = true;
            }
            else
            {
                LoadBasicHelper.Instance.isEffiCheck = false;
            }
        }

        private void btnLeaveMsg_Click(object sender, EventArgs e)
        {

        }

        private void btnChange_Click(object sender, EventArgs e)
        {

        }

        private void btnFindWeight_Click(object sender, EventArgs e)
        {
            try
            {
                rchRoadMap.Text = "";
                if (MemberInfo.Instance.token == "")
                {
                    MessageBox.Show("未登录授权");
                    return;
                }
                if (txtWeight.Text.Trim() == "")
                {
                    MessageBox.Show("查重单号不能为空");
                    return;
                }


                ArrayList arListWeightWaybills = new ArrayList();

                arListWeightWaybills = UtilityHelp.Instance.getInputParcels(txtWeight.Text.Trim());

                if (txtWeight.Text.Trim().Contains(","))
                {
                    txtWeight.Text = txtWeight.Text.Replace(",", "\n");
                }

                if (arListWeightWaybills.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    m_arListDisplayBarcodes.Clear();
                    foreach (ParcelBean parcel in arListWeightWaybills)
                    {
                        string strBarcode = parcel.wayBill;
                        sb.AppendLine(strBarcode);
                        m_arListDisplayBarcodes.Add(strBarcode);
                    }

                    this.txtBarcodes.Text = sb.ToString();
                }



                rchRoadMap.Text = "开始查重...";
                WeightHelperGen.Instance.BeginAnalyThread(arListWeightWaybills, "");
                txtWeight.Text = "";
            }
            catch (Exception ex)
            {

            }
        }

        private void btnCancelInter_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //临时
            //return;
            if (isUsing4Delay)
            {
                return;
            }
            timer1.Enabled = false;
            try
            {

                DateTime dtNow = System.DateTime.Now;
                TimeSpan ts = dtNow - WeightHelperGen.Instance.dtLastKeepAlive;
                if (ts.TotalSeconds > 60 * 3 || isFirstStart)
                {

                    this.rchRoadMap.Text = "";
                    ArrayList arListBarcode = new ArrayList();
                    ArrayList arListBarcodeSite = new ArrayList();
                    ArrayList arListTokens = new ArrayList();
                    int totalRegSucessRes = 0;
                    ArrayList arListAllSites = new ArrayList();
                    foreach (DictionaryEntry de in StoParams.Instance.htDifferentSiteBarcodeInfo)
                    {
                        arListBarcode.Add(de.Value.ToString());
                        arListBarcodeSite.Add(de.Key.ToString() + "$" + de.Value.ToString());

                        string pickName = de.Key.ToString();
                        if (!arListAllSites.Contains(pickName))
                        {
                            arListAllSites.Add(pickName);
                        }
                        if (StoParams.Instance.htRegInfo.ContainsKey(pickName))
                        {
                            ArrayList arListRegBeans = (ArrayList)StoParams.Instance.htRegInfo[pickName];
                            foreach (RegBean regBean in arListRegBeans)
                            {
                                string token = regBean.token;
                                ts = System.DateTime.Now - regBean.dtLastHeartBeat;
                                if (ts.TotalMinutes > 5 || isFirstStart)
                                {
                                    if (WeightHelperGen.Instance.keepAlive(de.Value.ToString(), token, pickName))
                                    {
                                        totalRegSucessRes++;
                                        regBean.dtLastHeartBeat = System.DateTime.Now;
                                        regBean.errorTimes = 0;
                                    }
                                    else
                                    {
                                        regBean.errorTimes++;
                                    }
                                }

                            }
                        }

                    }

                    if (totalRegSucessRes > 0)
                    {
                        foreach (DictionaryEntry de in StoParams.Instance.htRegInfo)
                        {
                            string siteName = de.Key.ToString();
                            ArrayList arListRegBeans = (ArrayList)de.Value;
                            ArrayList arListDel = new ArrayList();
                            foreach (RegBean regBean in arListRegBeans)
                            {
                                if (regBean.errorTimes > 30)
                                {
                                    arListDel.Add(regBean);
                                }
                                else
                                {
                                    string token = regBean.token;
                                    string regSiteID = regBean.regSiteID;
                                    string regSiteCode = regBean.regSiteCode;
                                    string regWechate = regBean.regWechate;
                                    string user = regBean.user;

                                    string addLine = token + "$" + siteName + "$" + regSiteID + "$" + regSiteCode + "$" + regWechate + "$" + user;
                                    arListTokens.Add(addLine);
                                }

                            }
                            foreach (RegBean regBean in arListDel)
                            {
                                if (arListRegBeans.Contains(regBean))
                                {
                                    arListRegBeans.Remove(regBean);
                                }
                            }
                            //RegBean regBean = (RegBean)de.Value;


                        }
                    }

                    FrameDecoderManager.Instance.lastSendRes = System.DateTime.Now;
                    logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.BarcodeSitePath, arListBarcodeSite);




                    if (arListTokens.Count > 0)
                    {
                        logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.TokenSitePath, arListTokens);
                    }

                    //临时
                    /*ArrayList arList = new ArrayList();
                    arList.Add("JT5159662363312");
                    arList.Add("JT5159662416042");
                    arList.Add("JT5159662117236");
                    LanshouHelperGen.Instance.parseLanshou(arList);*/




                }


            }
            catch (Exception ex)
            {

            }
            isFirstStart = false;
            timer1.Enabled = true;
        }

        private void btnImportZC_Click(object sender, EventArgs e)
        {
            int curRow = 0;
            string curWaybillNo = "";
            try
            {
                FrmSpeedZC frmSpeedZC = new FrmSpeedZC();
                frmSpeedZC.ShowDialog();

                StoParams.Instance.isZCOperater = true;
                sbZC.Clear();
                isUsing4Delay = true;
                StoParams.Instance.isInAddZCProcess = true;

                /*int curSpeed = StoParams.Instance.speed;
                int min = 6000;
                int max = 10000;

                ZhongCaiHelperGen.Instance.getMillSeconds(curSpeed,out min, out max);*/
                string outdir = "";
                //UtilityHelp.Instance.genStaticExcel(out outdir, "shaxi", "跟单统计 2023-07-19");
                rchRoadMap.Text = "";
                string path = @"";
                OpenFileDialog ofdg = new OpenFileDialog();
                if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    path = ofdg.FileName;//得到选择的文件的完整路径
                }
                else
                {
                    return;
                }


                string outPutDir = this.txtOutput.Text;
                if (!Directory.Exists(outPutDir))
                {
                    MessageBox.Show("批量仲裁，请先选择结果文件输出目录");
                    return;
                }



                



                StoParams.Instance.outputDir = outPutDir;

                Worksheet sheet1 = UtilityExcel.Instance.GetWorksheet(path, 0);
                int rowCount = sheet1.Cells.Rows.Count;
                StringBuilder sb = new StringBuilder();
                ArrayList arListZcBeans = new ArrayList();
                ArrayList arListWayBills = new ArrayList();
                if (rowCount < 1)
                {
                    MessageBox.Show("未解析到有效的仲裁文件");
                    return;
                }
                
                for (int i = 1; i < rowCount; i++)
                {
                    curRow++;
                    if(curRow==30)
                    {
                        int a = 0;
                    }
                    ZcBean zcBean = new ZcBean();
                    Row row = sheet1.Cells.Rows[i];
                    if (row.IsBlank)
                    {
                        continue;
                    }
                    string wayBillNo = row[0].Value.ToString();
                    curWaybillNo = wayBillNo;
                    string header = "第" + i.ToString() + "行";
                    if (!wayBillNo.StartsWith("JT"))
                    {
                        sb.AppendLine(header + " 单号" + wayBillNo + "不正确");
                        continue;
                    }

                    string delayType = row[1].Value.ToString();
                    if (delayType == "")
                    {
                        sb.AppendLine(header + " 一级延误类型" + "为空");
                        continue;
                    }

                    string secondDelayType = row[2].Value.ToString();
                    if (secondDelayType == "")
                    {
                        sb.AppendLine(header + " 二级延误类型" + "为空");
                        continue;
                    }
                    string delayDays = "";
                    if(row[3].Value!=null)
                    {
                        delayDays = row[3].Value.ToString();
                        if (delayDays == "" && !secondDelayType.Contains("私自退"))
                        {
                            sb.AppendLine(header + " 延误天数" + "为空");
                            continue;
                        }
                    }
                    
                    int intDays = 0;
                    if(!delayType.Contains("私自退"))
                    {
                        if (!int.TryParse(delayDays, out intDays))
                        {
                            sb.AppendLine(header + " 延误天数" + delayDays + "非法");
                            continue;
                        }
                    }
                    

                    string goodsValue = row[4].Value.ToString();
                    int intGoodsVal = 0;
                    if (!int.TryParse(goodsValue, out intGoodsVal))
                    {
                        sb.AppendLine(header + " 物品价值" + goodsValue + "非法");
                        continue;
                    }
                    string goodsName = row[5].Value.ToString();
                    if (goodsName == "")
                    {
                        sb.AppendLine(header + " 物品名称" + goodsName + "非法");
                        continue;
                    }


                    string dutySites = row[6].Value.ToString();
                    if (dutySites == "")
                    {
                        sb.AppendLine(header + " 责任网点" + "为空");
                        continue;
                    }

                    string desc = row[7].Value.ToString();
                    if (desc == "")
                    {
                        sb.AppendLine(header + " 责任说明" + "为空");
                        continue;
                    }
                    if (!arListWayBills.Contains(wayBillNo))
                    {
                        arListWayBills.Add(wayBillNo);
                        zcBean.wayBillNo = wayBillNo;
                        zcBean.errorType = delayType;
                        zcBean.firstType = delayType;
                        zcBean.secondType = secondDelayType;


                        zcBean.delayDays = delayDays;
                        zcBean.goodsValue = goodsValue;
                        zcBean.dutySite = dutySites;
                        zcBean.errorMsg = desc;
                        zcBean.goodsName = goodsName;
                        arListZcBeans.Add(zcBean);
                    }



                }
                DialogResult MsgBoxResult;
                MsgBoxResult = MessageBox.Show("当前登录的网点是：" + StoParams.Instance.register_site
                    + " 登录用户:" + StoParams.Instance.register_user + " 导入"
                    + arListWayBills.Count.ToString() + "待仲裁数据，请确定要批量自动申请仲裁吗？",//对话框的显示内容
                "确定仲裁",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Exclamation,
                MessageBoxDefaultButton.Button2);

                if (MsgBoxResult != DialogResult.Yes)//如果对话框的返回值是YES（按"Y"按钮）
                {
                    return;
                }

                //FrmSpeedSelect frmSpeed = new FrmSpeedSelect();
                //frmSpeed.ShowDialog();
                if(StoParams.Instance.register_user==null|| StoParams.Instance.register_user=="")
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }
                if(!StoParams.Instance.htRegsiteToken.ContainsKey(StoParams.Instance.register_user))
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }

                string curUserToken = StoParams.Instance.htRegsiteToken[StoParams.Instance.register_user].ToString();
                ZhongCaiHelperGen.Instance.BeginAnalyNormalZCThread(arListZcBeans, curUserToken);
            }
            catch (Exception ex)
            {
                MessageBox.Show("未能正常解析excel文件，是否有空行 当前单号 "+ curWaybillNo + " 行"+ curRow);

            }
        }



        private void btnImportNTZC_Click(object sender, EventArgs e)
        {
            int curRow = 0;
            string curWaybillNo = "";
            try
            {
                FrmSpeedZC frmSpeedZC = new FrmSpeedZC();
                frmSpeedZC.ShowDialog();

                StoParams.Instance.isZCOperater = true;
                sbZC.Clear();
                isUsing4Delay = true;
                StoParams.Instance.isInAddZCProcess = true;

                /*int curSpeed = StoParams.Instance.speed;
                int min = 6000;
                int max = 10000;

                ZhongCaiHelperGen.Instance.getMillSeconds(curSpeed,out min, out max);*/
                string outdir = "";
                //UtilityHelp.Instance.genStaticExcel(out outdir, "shaxi", "跟单统计 2023-07-19");
                rchRoadMap.Text = "";
                string path = @"";
                OpenFileDialog ofdg = new OpenFileDialog();
                if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    path = ofdg.FileName;//得到选择的文件的完整路径
                }
                else
                {
                    return;
                }


                string outPutDir = this.txtOutput.Text;
                if (!Directory.Exists(outPutDir))
                {
                    MessageBox.Show("批量仲裁，请先选择结果文件输出目录");
                    return;
                }







                StoParams.Instance.outputDir = outPutDir;

                Worksheet sheet1 = UtilityExcel.Instance.GetWorksheet(path, 0);
                int rowCount = sheet1.Cells.Rows.Count;
                StringBuilder sb = new StringBuilder();
                ArrayList arListZcBeans = new ArrayList();
                ArrayList arListWayBills = new ArrayList();
                if (rowCount < 1)
                {
                    MessageBox.Show("未解析到有效的仲裁文件");
                    return;
                }

                for (int i = 1; i < rowCount; i++)
                {
                    curRow++;
                    if (curRow == 30)
                    {
                        int a = 0;
                    }
                    ZcBean zcBean = new ZcBean();
                    Row row = sheet1.Cells.Rows[i];
                    if (row.IsBlank)
                    {
                        continue;
                    }
                    string wayBillNo = row[0].Value.ToString();
                    curWaybillNo = wayBillNo;
                    string header = "第" + i.ToString() + "行";
                    if (!wayBillNo.StartsWith("JT"))
                    {
                        sb.AppendLine(header + " 单号" + wayBillNo + "不正确");
                        continue;
                    }

                    string delayType = row[1].Value.ToString();
                    if (delayType == "")
                    {
                        sb.AppendLine(header + " 一级延误类型" + "为空");
                        continue;
                    }

                    string secondDelayType = row[2].Value.ToString();
                    if (secondDelayType == "")
                    {
                        sb.AppendLine(header + " 二级延误类型" + "为空");
                        continue;
                    }

                    string thirdDelayType = row[3].Value.ToString();
                    if (thirdDelayType == "")
                    {
                        sb.AppendLine(header + " 三级延误类型" + "为空");
                        continue;
                    }

                    string delayDays = "";
                    if (row[4].Value != null)
                    {
                        delayDays = row[4].Value.ToString();
                        if (delayDays == "" && !secondDelayType.Contains("私自退"))
                        {
                            sb.AppendLine(header + " 延误天数" + "为空");
                            continue;
                        }
                    }

                    int intDays = 0;
                    if (!delayType.Contains("私自退"))
                    {
                        if (!int.TryParse(delayDays, out intDays))
                        {
                            sb.AppendLine(header + " 延误天数" + delayDays + "非法");
                            continue;
                        }
                    }


                    string goodsValue = row[5].Value.ToString();
                    int intGoodsVal = 0;
                    if (!int.TryParse(goodsValue, out intGoodsVal))
                    {
                        sb.AppendLine(header + " 物品价值" + goodsValue + "非法");
                        continue;
                    }
                    string goodsName = row[6].Value.ToString();
                    if (goodsName == "")
                    {
                        sb.AppendLine(header + " 物品名称" + goodsName + "非法");
                        continue;
                    }


                    string dutySites = row[7].Value.ToString();
                    if (dutySites == "")
                    {
                        sb.AppendLine(header + " 责任网点" + "为空");
                        continue;
                    }

                    string desc = row[8].Value.ToString();
                    if (desc == "")
                    {
                        sb.AppendLine(header + " 责任说明" + "为空");
                        continue;
                    }
                    if (!arListWayBills.Contains(wayBillNo))
                    {
                        arListWayBills.Add(wayBillNo);
                        zcBean.wayBillNo = wayBillNo;
                        zcBean.errorType = delayType;
                        zcBean.firstType = delayType;
                        zcBean.secondType = secondDelayType;


                        zcBean.delayDays = delayDays;
                        zcBean.goodsValue = goodsValue;
                        zcBean.dutySite = dutySites;
                        zcBean.errorMsg = desc;
                        zcBean.goodsName = goodsName;
                        zcBean.thirdType = thirdDelayType;
                        arListZcBeans.Add(zcBean);
                    }



                }
                DialogResult MsgBoxResult;
                MsgBoxResult = MessageBox.Show("当前登录的网点是：" + StoParams.Instance.register_site
                    + " 登录用户:" + StoParams.Instance.register_user + " 导入"
                    + arListWayBills.Count.ToString() + "待仲裁数据，请确定要批量自动申请仲裁吗？",//对话框的显示内容
                "确定仲裁",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Exclamation,
                MessageBoxDefaultButton.Button2);

                if (MsgBoxResult != DialogResult.Yes)//如果对话框的返回值是YES（按"Y"按钮）
                {
                    return;
                }

                //FrmSpeedSelect frmSpeed = new FrmSpeedSelect();
                //frmSpeed.ShowDialog();
                if (StoParams.Instance.register_user == null || StoParams.Instance.register_user == "")
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }
                if (!StoParams.Instance.htRegsiteToken.ContainsKey(StoParams.Instance.register_user))
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }

                string curUserToken = StoParams.Instance.htRegsiteToken[StoParams.Instance.register_user].ToString();
                ZhongCaiHelperGen.Instance.BeginAnalyNormalZCThread(arListZcBeans, curUserToken);
            }
            catch (Exception ex)
            {
                MessageBox.Show("未能正常解析excel文件，是否有空行 当前单号 " + curWaybillNo + " 行" + curRow);

            }
        }


        private void btnTest_Click(object sender, EventArgs e)
        {
            try
            {
                string mt = this.tbWaybillNo.Text.Trim();
                if (mt == "")
                {
                    MessageBox.Show("坐标不能为空");
                    return;
                }
                string resMsg = "up:" + mt;
                resMsg = resMsg.TrimEnd(new char[] { '\r', '\n' });
                if (resMsg.Length > 4)
                {
                    byte[] resMsgContent = System.Text.Encoding.Default.GetBytes(resMsg);
                    Program.weServer.sendContent(resMsgContent);
                }

            }
            catch (Exception ex)
            {

            }
        }

        private void btnDown_Click(object sender, EventArgs e)
        {
            try
            {
                string mt = this.tbWaybillNo.Text.Trim();
                if (mt == "")
                {
                    MessageBox.Show("坐标不能为空");
                    return;
                }
                string resMsg = "down:" + mt;
                resMsg = resMsg.TrimEnd(new char[] { '\r', '\n' });
                if (resMsg.Length > 4)
                {
                    byte[] resMsgContent = System.Text.Encoding.Default.GetBytes(resMsg);
                    Program.weServer.sendContent(resMsgContent);
                }
            }
            catch (Exception ex)
            {

            }
        }





        private void menuPosConfig_Click(object sender, EventArgs e)
        {

        }

        private void btnGenStaticTotal_Click(object sender, EventArgs e)
        {
            try
            {
                SelectTimeBean selectBean = new SelectTimeBean();
                selectBean.startTime = this.dateTimePicker1.Value;
                selectBean.endTime = this.dateTimePicker2.Value;

                DateTime dtStart = selectBean.startTime;
                DateTime dtEnd = selectBean.endTime;
                JObject jObj = new JObject();
                jObj["current"] = 1;
                jObj["size"] = 20;
                jObj["startDates"] = dtStart.ToString("yyyy-MM-dd HH:mm:ss");
                jObj["endDates"] = dtEnd.ToString("yyyy-MM-dd HH:mm:ss"); ;
                jObj["siteCode"] = StoParams.Instance.register_code;
                jObj["countryId"] = "1";
                string postUrl = "https://jmsgw.jtexpress.com.cn/bigdataoperatingplatform/receiveMonitor/allTotal";
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string routeName = "newReceivingMonitoring";
                string messge = HttpClient.HttpUtil.Instance.PostCommon(postUrl, postData, routeName);
                int totalPages = 0;
                ArrayList arListbarcodes = new ArrayList();
                if (messge.Contains("请求成功"))
                {
                    if (messge.Contains("data"))
                    {
                        JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(messge);

                        JToken dataObj = jsonObjRes["data"];
                        string totalCount = Convert.ToString(dataObj["receiveCntTotal"].ToString());
                        StoParams.Instance.totalParcels = Convert.ToInt32(totalCount);
                        this.rchRoadMap.Text = "操作总量:" + StoParams.Instance.totalParcels.ToString();

                    }
                }

            }//try
            catch (Exception ex)
            {

            }
        }

        private void btnImportLvBoard_Click(object sender, EventArgs e)
        {
            try
            {
                if (MemberInfo.Instance.token == "")
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }
                //临时
                if (!StoParams.Instance.isRegByMachine)
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }
                txtLeavedBarcodes.Text = "";
                txtFailedBarcodes.Text = "";
                ArrayList arListCurImport = new ArrayList();
                OpenFileDialog ofdg = new OpenFileDialog();
                if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string file = ofdg.FileName;//得到选择的文件的完整路径
                    int totalCount = 0;
                    arListCurImport = UtilityHelp.Instance.getBarCodeFromFileParcel(file, out totalCount);
                    if (arListCurImport.Count == 0)
                    {
                        MessageBox.Show("没有取到运单号");
                        return;
                    }
                    int curFileCount = 0;

                    lblImportResult.Text = "导入条数：" + totalCount.ToString();
                    txbImport.Text = "导入条数：" + totalCount.ToString();

                    anylizeWaybillCount = 0;
                    LeaveMessageHelperAssignDelay.Instance.BeginAnalyThread(arListCurImport, "departure");

                }


            }
            catch (Exception ex)
            {

            }
        }

        private void btnStaticSites_Click(object sender, EventArgs e)
        {
            try
            {
                string strTxt = txtLeavedBarcodes.Text;
                string[] arrTexts = strTxt.Split('\n');
                string res = UtilityHelp.Instance.getStaticText(arrTexts);
                rchRoadMap.Text = res;




            }
            catch (Exception ex)
            {

            }
        }

        private void btnTestSendMsg_Click(object sender, EventArgs e)
        {
            try
            {
                var client = new RestClient("http://127.0.0.1:9090");
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                client.UserAgent = "Apifox/1.0.0 (http://127.0.0.1:9090)";
                request.AddHeader("Content-Type", "application/json");
                var body = @"{
" + "\n" +
                @"    ""data"": {
" + "\n" +
                @"        ""to_wxid"": ""dezhou020792"",
" + "\n" +
                @"        ""content"": ""https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png""
" + "\n" +
                @"    },
" + "\n" +
                @"    ""client_id"": 1,
" + "\n" +
                @"    ""type"": ""MT_SEND_TEXTMSG""
" + "\n" +
                @"}";
                request.AddParameter("application/json", body, RestSharp.ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);
                MessageBox.Show(response.Content);
                Console.WriteLine(response.Content);
            }
            catch (Exception ex)
            {

            }
        }

        private void btnTestSendMsg_Click_1(object sender, EventArgs e)
        {
            ReplyHelper.Instance.replySuperMsg("44222003726@chatroom", "测试艾特{$@}", "1688857558397067", "1688857558397067");

            //ReplyHelper.Instance.replyQQMsg("917250636", "测试发送[@93620130]", "3365017936");
            /*string path = "";
            string roomID = "21148051106@chatroom";
            string line = "跟单统计";
            UtilityHelp.Instance.genStaticExcel(out path, roomID, line, "dezhou020792");*/



            string mac = UtilityHelp.Instance.GetMACAddress();

            //LogHelper.Instance.writeLog( "测试 " + mac);

            return;
            Hashtable htAllGroup = new Hashtable();
            string ad = "";
            //UtilityHelp.Instance.initAllOutboundType(out ad);



            //OutboundProblemAckGen.Instance.BeginAnalyThread("2023-10-14", "2023-10-15", "19197655976@chatroom", "dezhou020792");
            /*string barcode = "JT5211412491964";
             CustomerBean customerBean = new CustomerBean();
             UtilityHelp.Instance.getMsgList(barcode, customerBean);
             UtilityHelp.Instance.getCustomerInfo(customerBean);

            JObject jObj = new JObject();
             jObj["ServiceName"] = "register";
             JArray jar = new JArray();
             foreach(DictionaryEntry de in FrameDecoderManager.Instance.htAllRooms)
             {
                 jar.Add(de.Key.ToString());
             }

             //jar[0] = "123456";
             jObj["roomids"] = jar;
             string strSendContend = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
             strSendContend = "we " + strSendContend + "\r\n";
             byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(strSendContend);
             //MessageProClient.Instance.SendContent(contentBytes);*/
          

           


            return;
            /*var client = new RestClient("http://127.0.0.1:9090");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            client.UserAgent = "Apifox/1.0.0 (http://127.0.0.1:9090)";
            request.AddHeader("Content-Type", "application/json");
            var body = @"{
" + "\n" +
            @"    ""data"": {
" + "\n" +
            @"        ""room_wxid"": ""34469078841@chatroom""
" + "\n" +
            @"    },
" + "\n" +
            @"    ""client_id"": 1,
" + "\n" +
            @"    ""type"": ""MT_DATA_CHATROOM_MEMBERS_MSG""
" + "\n" +
            @"}";
            request.AddParameter("application/json", body, RestSharp.ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            MessageBox.Show(response.Content);*/
        }



        public void initSiteMessage()
        {
            try
            {
                JObject jObj = new JObject();
                jObj["ServiceName"] = "siteRegister";
                JArray jar = new JArray();
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htAllSites)
                {
                    jar.Add(de.Key.ToString());
                }
                jObj["sites"] = jar;
                string strSendContend = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                strSendContend = "we " + strSendContend + "\r\n";
                byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(strSendContend);
                MessageProClient.Instance.SendContent(contentBytes);
            }
            catch (Exception ex)
            {

            }
        }

        public void initQQSiteMessage()
        {
            try
            {
                JObject jObj = new JObject();
                jObj["ServiceName"] = "siteRegister";
                JArray jar = new JArray();
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htAllSites)
                {
                    if(!de.Key.ToString().Contains("@"))
                    {
                        jar.Add(de.Key.ToString());
                    }
                    
                }
                jObj["sites"] = jar;
                string strSendContend = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                strSendContend = "we " + strSendContend + "\r\n";
                byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(strSendContend);
                MessageQQProClient.Instance.SendContent(contentBytes);
            }
            catch (Exception ex)
            {

            }
        }

        public void initRegMessage()
        {
            try
            {
                JObject jObj = new JObject();
                jObj["ServiceName"] = "register";
                JArray jar = new JArray();
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htAllRooms)
                {
                    jar.Add(de.Key.ToString());
                }
                jObj["roomids"] = jar;
                string strSendContend = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                strSendContend = "we " + strSendContend + "\r\n";
                byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(strSendContend);
                MessageProClient.Instance.SendContent(contentBytes);
            }
            catch (Exception ex)
            {

            }
        }


        public void initRegQQMessage()
        {
            try
            {
                JObject jObj = new JObject();
                jObj["ServiceName"] = "register";
                JArray jar = new JArray();
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htAllRooms)
                {
                    if(!de.Key.ToString().Contains("@"))
                    {
                        jar.Add(de.Key.ToString());
                    }
                    
                }
                jObj["roomids"] = jar;
                string strSendContend = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                strSendContend = "we " + strSendContend + "\r\n";
                byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(strSendContend);
                MessageQQProClient.Instance.SendContent(contentBytes);
            }
            catch (Exception ex)
            {

            }
        }

        public byte[] ToBytes(uint num, int size)
        {
            Contract.Assume(size <= 4);
            return BitConverter.GetBytes(num).Take(size).Reverse().ToArray();
        }
        private void timer1_Tick_1(object sender, EventArgs e)
        {
            if (isUsing4Delay)
            {
                if(StoParams.Instance.sbZCAutoAdd.ToString().Length>4)
                {
                    if(this.rchRoadMap.Text != StoParams.Instance.sbZCAutoAdd.ToString())
                    {
                        this.rchRoadMap.Text = StoParams.Instance.sbZCAutoAdd.ToString();
                    }
                    
                }
                return;
            }
            timer1.Enabled = false;
            try
            {

                DateTime dtNow = System.DateTime.Now;
                TimeSpan ts = dtNow - WeightHelperGen.Instance.dtLastKeepAlive;
                if (ts.TotalSeconds > 60 * 3 || isFirstStart)
                {

                    this.rchRoadMap.Text = "";
                    ArrayList arListBarcode = new ArrayList();
                    ArrayList arListBarcodeSite = new ArrayList();
                    ArrayList arListTokens = new ArrayList();
                    int totalRegSucessRes = 0;
                    ArrayList arListAllSites = new ArrayList();
                    foreach (DictionaryEntry de in StoParams.Instance.htDifferentSiteBarcodeInfo)
                    {
                        arListBarcode.Add(de.Value.ToString());
                        arListBarcodeSite.Add(de.Key.ToString() + "$" + de.Value.ToString());

                        string pickName = de.Key.ToString();
                        if (!arListAllSites.Contains(pickName))
                        {
                            arListAllSites.Add(pickName);
                        }
                        if (StoParams.Instance.htRegInfo.ContainsKey(pickName))
                        {
                            ArrayList arListRegBeans = (ArrayList)StoParams.Instance.htRegInfo[pickName];
                            foreach (RegBean regBean in arListRegBeans)
                            {
                                string token = regBean.token;
                                ts = System.DateTime.Now - regBean.dtLastHeartBeat;
                                if (ts.TotalMinutes > 5 || isFirstStart)
                                {
                                    if (WeightHelperGen.Instance.keepAlive(de.Value.ToString(), token, pickName))
                                    {
                                        totalRegSucessRes++;
                                        regBean.dtLastHeartBeat = System.DateTime.Now;
                                        regBean.errorTimes = 0;
                                    }
                                    else
                                    {
                                        regBean.errorTimes++;
                                    }
                                }

                            }
                        }

                    }

                    if (totalRegSucessRes > 0)
                    {
                        foreach (DictionaryEntry de in StoParams.Instance.htRegInfo)
                        {
                            string siteName = de.Key.ToString();
                            ArrayList arListRegBeans = (ArrayList)de.Value;
                            ArrayList arListDel = new ArrayList();
                            foreach (RegBean regBean in arListRegBeans)
                            {
                                if (regBean.errorTimes > 30)
                                {
                                    arListDel.Add(regBean);
                                }
                                else
                                {
                                    string token = regBean.token;
                                    string regSiteID = regBean.regSiteID;
                                    string regSiteCode = regBean.regSiteCode;
                                    string regWechate = regBean.regWechate;
                                    string user = regBean.user;

                                    string addLine = token + "$" + siteName + "$" + regSiteID + "$" + regSiteCode + "$" + regWechate+"$"+ user;
                                    arListTokens.Add(addLine);
                                }

                            }
                            foreach (RegBean regBean in arListDel)
                            {
                                if (arListRegBeans.Contains(regBean))
                                {
                                    arListRegBeans.Remove(regBean);
                                }
                            }
                            //RegBean regBean = (RegBean)de.Value;


                        }
                    }

                    FrameDecoderManager.Instance.lastSendRes = System.DateTime.Now;
                    logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.BarcodeSitePath, arListBarcodeSite);




                    if (arListTokens.Count > 0)
                    {
                        logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.TokenSitePath, arListTokens);
                    }


                    
                    //临时
                    /*ArrayList arList = new ArrayList();
                    arList.Add("JT5159662363312");
                    arList.Add("JT5159662416042");
                    arList.Add("JT5159662117236");
                    LanshouHelperGen.Instance.parseLanshou(arList);*/




                }


            }
            catch (Exception ex)
            {

            }
            isFirstStart = false;
            timer1.Enabled = true;
        }

        private void btnStaticSites_Click_1(object sender, EventArgs e)
        {
            try
            {
                WechatMsgBean wechatMsgBean = new WechatMsgBean();
                string strContent = "";
                string msg = "";
                JObject jObj = new JObject();
                jObj["ServiceName"] = "wechatMsg";
                jObj["roomid"] = "34469078841@chatroom";
                jObj["content"] = "JT34343432423";
                jObj["msgtime"] = wechatMsgBean.msgtime;
                jObj["msgtype"] = wechatMsgBean.msgtype;
                string strSendContend = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                //strSendContend = "we " + strSendContend + "\r\n";
                byte[]  contentBytes = System.Text.Encoding.UTF8.GetBytes(strSendContend);
                int length = contentBytes.Length;
                byte[] arrLength = ToBytes((uint)length, 4);
                byte[] newArr = arrLength.Concat(contentBytes).ToArray();
               // Program.weServer.sendContent(newArr, "34469078841@chatroom");
            }
            catch(Exception ex)
            {

            }
        }

        private void btnLanshou_Click(object sender, EventArgs e)
        {
          

            StoParams.Instance.totalParcels = 0;
            StoParams.Instance.curParces = 0;

            ArrayList arListLeaveMsgWaybills = new ArrayList();

            string allContent = rxtWaybills.Text.Trim();
            allContent = allContent.Replace("，", "");
            allContent = allContent.Replace(",", "");
            int curLoop = 0;

            logHelp.LogHelper.Instance.writeLog("开始解析揽收");

            if (allContent.Length > 16000)
            {
                while (allContent.Length > 16000)
                {
                    curLoop++;
                    char[] jt = "JT".ToCharArray();
                    int spintIndex = allContent.IndexOfAny(jt, 16000);
                    //string sub = allContent.Substring(0, allContent.IndexOfAny(jt, spintIndex));
                    string sub = allContent.Substring(0, spintIndex);
                    ArrayList atlitTmp = UtilityHelp.Instance.getInputBarcodesAndAddr(sub, new TaskBean());
                    arListLeaveMsgWaybills.AddRange(atlitTmp);
                    allContent = allContent.Substring(spintIndex);


                }
                if (allContent.Length > 13 && allContent.Length < 16000)
                {
                    ArrayList atlitTmp = UtilityHelp.Instance.getInputBarcodesAndAddr(allContent, new TaskBean());
                    arListLeaveMsgWaybills.AddRange(atlitTmp);

                }

            }
            else
            {
                arListLeaveMsgWaybills = UtilityHelp.Instance.getInputBarcodesAndAddr(rxtWaybills.Text.Trim(), new TaskBean());
            }
            logHelp.LogHelper.Instance.writeLog("解析到个数："+ arListLeaveMsgWaybills.Count.ToString());
            //arListLeaveMsgWaybills = UtilityHelp.Instance.getInputBarcodesAndAddr(txtCJWaybills.Text.Trim());
            rxtWaybills.Text = rxtWaybills.Text.Replace("，", ",");
            if (rxtWaybills.Text.Trim().Contains(","))
            {
                rxtWaybills.Text = rxtWaybills.Text.Replace(",", "\n");
            }
            //arListLeaveMsgWaybills.AddRange(txtCJWaybills.Text.Trim().Split('\n'));

            lblImportResult.Text = "输入条数：" + arListLeaveMsgWaybills.Count.ToString();
            txbImport.Text = "输入条数：" + arListLeaveMsgWaybills.Count.ToString();
            txtLSInfo.Text = "待揽收条数：" + arListLeaveMsgWaybills.Count.ToString() + " "; ;
            if (arListLeaveMsgWaybills.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                m_arListDisplayBarcodes.Clear();
                foreach (ParcelBean parcelBean in arListLeaveMsgWaybills)
                {
                    sb.AppendLine(parcelBean.wayBill);
                    m_arListDisplayBarcodes.Add(parcelBean.wayBill);
                }

                this.txtBarcodes.Text = sb.ToString();
            }



            rchRoadMap.Text = "开始留言...";
            LanshouHelperGen.Instance.BeginAnalyThread(arListLeaveMsgWaybills, "manual");
            //LeaveMessageHelperGen.Instance.BeginAnalyThread(arListLeaveMsgWaybills, "manual");
            rxtWaybills.Text = "";
        }

        private void btnLeaveMsg_Click_1(object sender, EventArgs e)
        {

        }

        private void banAutoUploadZC_Click(object sender, EventArgs e)
        {
            int curRowCount = 0;
            try
            {
                isUsing4Delay = true;
                StoParams.Instance.isInAddZCProcess = true;
                string outdir = "";
                //UtilityHelp.Instance.genStaticExcel(out outdir, "和顺", "跟单统计2023-07-19");
                rchRoadMap.Text = "";
                string path = @"";
                OpenFileDialog ofdg = new OpenFileDialog();
                if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    path = ofdg.FileName;//得到选择的文件的完整路径
                }


                string outPutDir = this.txtOutput.Text;
                if (!Directory.Exists(outPutDir))
                {
                    MessageBox.Show("批量仲裁，请先选择结果文件输出目录");
                    return;
                }
                StoParams.Instance.outputDir = outPutDir;

                Worksheet sheet1 = UtilityExcel.Instance.GetWorksheet(path, 0);
                int rowCount = sheet1.Cells.Rows.Count;
                StringBuilder sb = new StringBuilder();
                ArrayList arListZcBeans = new ArrayList();
                ArrayList arListWayBills = new ArrayList();
                if (rowCount < 1)
                {
                    MessageBox.Show("未解析到有效的仲裁文件");
                    return;
                }
                string firstJTbillCode = "";
                for (int i = 1; i < rowCount; i++)
                {
                    curRowCount = i;
                    ZcBean zcBean = new ZcBean();
                    Row row = sheet1.Cells.Rows[i];
                    if (row.IsBlank)
                    {
                        continue;
                    }
                    string wayBillNo = row[0].Value.ToString();
                    if(wayBillNo.Contains("JT"))
                    {
                        firstJTbillCode = wayBillNo;
                    }
                    string header = "第" + i.ToString() + "行";
                    if (!wayBillNo.StartsWith("JT"))
                    {
                        sb.AppendLine(header + " 单号" + wayBillNo + "不正确");
                        continue;
                    }

                    string delayType = row[1].Value.ToString();
                    if (delayType == "")
                    {
                        sb.AppendLine(header + " 一级延误类型" + "为空");
                        continue;
                    }

                    string secondDelayType = row[2].Value.ToString();
                    if (secondDelayType == "")
                    {
                        sb.AppendLine(header + " 二级延误类型" + "为空");
                        continue;
                    }
                    string delayDays = "";
                    if (row[3].Value != null)
                    {
                        delayDays = row[3].Value.ToString();
                        if (delayDays == "" && !secondDelayType.Contains("私自退"))
                        {
                            sb.AppendLine(header + " 延误天数" + "为空");
                            continue;
                        }
                    }

                    int intDays = 0;
                    if (!delayType.Contains("私自退"))
                    {
                        if (!int.TryParse(delayDays, out intDays))
                        {
                            sb.AppendLine(header + " 延误天数" + delayDays + "非法");
                            continue;
                        }
                    }


                    string goodsValue = row[4].Value.ToString();
                    int intGoodsVal = 0;
                    if (!int.TryParse(goodsValue, out intGoodsVal))
                    {
                        sb.AppendLine(header + " 物品价值" + goodsValue + "非法");
                        continue;
                    }
                    string goodsName = row[5].Value.ToString();
                    if (goodsName == "")
                    {
                        sb.AppendLine(header + " 物品名称" + goodsName + "非法");
                        continue;
                    }


                    string dutySites = row[6].Value.ToString();
                    if (dutySites == "")
                    {
                        sb.AppendLine(header + " 责任网点" + "为空");
                        continue;
                    }

                    string desc = row[7].Value.ToString();
                    if (desc == "")
                    {
                        sb.AppendLine(header + " 责任说明" + "为空");
                        continue;
                    }
                    if (!arListWayBills.Contains(wayBillNo))
                    {
                        arListWayBills.Add(wayBillNo);
                        zcBean.wayBillNo = wayBillNo;
                        zcBean.errorType = delayType;
                        zcBean.firstType = delayType;
                        zcBean.secondType = secondDelayType;


                        zcBean.delayDays = delayDays;
                        zcBean.goodsValue = goodsValue;
                        zcBean.dutySite = dutySites;
                        zcBean.errorMsg = desc;
                        zcBean.goodsName = goodsName;
                        arListZcBeans.Add(zcBean);
                    }



                }

                FrmMode frmMode = new FrmMode();
                frmMode.ShowDialog();
              
                if(StoParams.Instance.autoMode =="")
                {
                    return;
                }

                DialogResult MsgBoxResult;
                MsgBoxResult = MessageBox.Show("当前登录的网点是：" + StoParams.Instance.register_site
                    + " 登录用户:" + StoParams.Instance.register_user + " 导入"
                    + arListWayBills.Count.ToString() + "待仲裁数据，请确定要批量自动申请仲裁吗("+ StoParams.Instance.autoMode+ ")？",//对话框的显示内容
                "确定仲裁",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Exclamation,
                MessageBoxDefaultButton.Button2);

                if (MsgBoxResult != DialogResult.Yes)//如果对话框的返回值是YES（按"Y"按钮）
                {
                    return;
                }
                if(StoParams.Instance.register_user==null)
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }
                if(!StoParams.Instance.htRegsiteToken.ContainsKey(StoParams.Instance.register_user))
                {
                    MessageBox.Show("请重新复制当前用户的登录信息:"+ StoParams.Instance.register_user);
                    return;
                }
                string pickName = "";
                string orderSource = "";
                string curSiteToken = "";
                string customerName = "";
                string curUserToken = StoParams.Instance.htRegsiteToken[StoParams.Instance.register_user].ToString();
                if (!UtilityHelp.Instance.resetToken(firstJTbillCode, out pickName, out orderSource, out curSiteToken,out customerName))
                {
                    if(curUserToken!= curSiteToken)
                    {
                        MessageBox.Show("请重新复制当前用户的登录信息:" + StoParams.Instance.register_user);
                        return;
                    }
                }
                
                ZhongCaiHelperGen.Instance.BeginAnalyThread(arListZcBeans, curUserToken,true, StoParams.Instance.speed);
            }
            catch(Exception ex)
            {
                if(ex.ToString().Contains("未将对象"))
                {
                    MessageBox.Show("自动提交定时仲裁失败，ex:" + ex.ToString() + " 当前行：" + curRowCount.ToString());
                }
                else
                {
                    MessageBox.Show("自动提交定时仲裁失败，ex:" + ex.ToString());
                }
               
            }
        }

        private void btnSignInbound_Click(object sender, EventArgs e)
        {
            try
            {
               
                StoParams.Instance.totalParcels = 0;
                StoParams.Instance.curParces = 0;
                StoParams.Instance.addCommentParcels = 0;
                if (StoParams.Instance.htTokenSign.Count==0)
                {
                    MessageBox.Show("请先登录机器人");
                    return;
                }
                txtFailedBarcodes.Text = "";
                txtLeavedBarcodes.Text = "";
                if (StoParams.Instance.firstProblemBean.id == 0)
                {
                    MessageBox.Show("请先设置留言模板以及类型");
                    return;
                }
                if (StoParams.Instance.inboundTemplete == "")
                {
                    MessageBox.Show("请先设置留言模板以及类型");
                    return;
                }

                ArrayList arListLeaveMsgWaybills = new ArrayList();

                string allContent = txtSignInbound.Text.Trim();
                allContent = allContent.Replace("，", "");
                allContent = allContent.Replace(",", "");
                int curLoop = 0;

                logHelp.LogHelper.Instance.writeLog("开始解析单号...");

                if (allContent.Length > 16000)
                {
                    while (allContent.Length > 16000)
                    {
                        curLoop++;
                        char[] jt = "JT".ToCharArray();
                        int spintIndex = allContent.IndexOfAny(jt, 16000);
                        //string sub = allContent.Substring(0, allContent.IndexOfAny(jt, spintIndex));
                        string sub = allContent.Substring(0, spintIndex);
                        ArrayList atlitTmp = UtilityHelp.Instance.getInputBarcodesAndAddr(sub, new TaskBean());
                        arListLeaveMsgWaybills.AddRange(atlitTmp);
                        allContent = allContent.Substring(spintIndex);

                    }
                    if (allContent.Length > 13 && allContent.Length < 1600)
                    {
                        ArrayList atlitTmp = UtilityHelp.Instance.getInputBarcodesAndAddr(allContent, new TaskBean());
                        arListLeaveMsgWaybills.AddRange(atlitTmp);
                    }

                }
                else
                {
                    arListLeaveMsgWaybills = UtilityHelp.Instance.getInputBarcodesAndAddr(txtSignInbound.Text.Trim(), new TaskBean());
                }
                txtSignInbound.Text = "";
                logHelp.LogHelper.Instance.writeLog("解析到个数：" + arListLeaveMsgWaybills.Count.ToString());
                InboundSignMessageHelper.Instance.BeginAnalyThread(arListLeaveMsgWaybills, "");
                


            }
            catch(Exception ex)
            {
                MessageBox.Show("btnSignInbound_Click，ex:" + ex.ToString());
            }
            
        }

        private void menuInboundSetting_Click(object sender, EventArgs e)
        {
            FrmInboundSetting frmInbound = new FrmInboundSetting();
            frmInbound.ShowDialog();
        }

        private void btnIntercept_Click_1(object sender, EventArgs e)
        {
            if (MemberInfo.Instance.token == "")
            {
                MessageBox.Show("未登录授权");
                return;
            }
            /*if (StoParams.Instance.probleTypeSubject == "")
            {
                MessageBox.Show("请在菜单 个性设置-拦截类型设置 里设置拦截类型");
                return;
            }*/
            if (tbWayBillDep.Text.Trim() == "")
            {
                MessageBox.Show("单号不能为空");
                return;
            }
            /*if (MemberInfo.Instance.templeteAssign == "" || MemberInfo.Instance.templeteTransfer == ""
                    || MemberInfo.Instance.templeteQS == "" || MemberInfo.Instance.templeteReturn == "")
            {
                MessageBox.Show("未设置留言模板");
                return;
            }*/

            /*this.tbWaybillNo.Text = tbWayBillDep.Text.Trim();
            ArrayList arListInterCeptWaybills = new ArrayList();
            if(tbWayBillDep.Text.Trim().Contains(","))
            {
                tbWayBillDep.Text = tbWayBillDep.Text.Replace(",", "\n");
            }
            arListInterCeptWaybills.AddRange(tbWayBillDep.Text.Trim().Split('\n'));*/

            ArrayList arListLeaveMsgWaybills = new ArrayList();

            arListLeaveMsgWaybills = UtilityHelp.Instance.getInputBarcodesAndAddr(tbWayBillDep.Text.Trim(), new TaskBean());
            foreach (ParcelBean parcleBean in arListLeaveMsgWaybills)
            {
                UtilityHelp.Instance.parseIsYishi(parcleBean);
            }
            rchRoadMap.Text = "";
            InterceptMessageHelper.Instance.BeginAnalyThread(arListLeaveMsgWaybills, "");
            tbWayBillDep.Text = "";
        }

        private void btnStaticMsg_Click(object sender, EventArgs e)
        {
            try
            {
                if (MemberInfo.Instance.token == "")
                {
                    MessageBox.Show("未登录授权");
                    return;
                }

                if (rchMsgboard.Text.Trim() == "")
                {
                    MessageBox.Show("单号不能为空");
                    return;
                }
                /*if (MemberInfo.Instance.templeteAssign == "" || MemberInfo.Instance.templeteTransfer == ""
                        || MemberInfo.Instance.templeteQS == "" || MemberInfo.Instance.templeteReturn == "")
                {
                    MessageBox.Show("未设置留言模板");
                    return;
                }*/

                /*this.tbWaybillNo.Text = tbWayBillDep.Text.Trim();
                ArrayList arListInterCeptWaybills = new ArrayList();
                if(tbWayBillDep.Text.Trim().Contains(","))
                {
                    tbWayBillDep.Text = tbWayBillDep.Text.Replace(",", "\n");
                }
                arListInterCeptWaybills.AddRange(tbWayBillDep.Text.Trim().Split('\n'));*/

                ArrayList arListLeaveMsgWaybills = new ArrayList();

                arListLeaveMsgWaybills = UtilityHelp.Instance.getInputBarcodesAndAddr(rchMsgboard.Text.Trim(), new TaskBean());
    
                rchRoadMap.Text = "";
                isClickManual = true;
                GetMsgBoardHelperGen.Instance.BeginAnalyThread(arListLeaveMsgWaybills, "");
                tbWayBillDep.Text = "";
            }
            catch(Exception ex)
            {

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (MemberInfo.Instance.token == "")
            {
                MessageBox.Show("请先设置机器人在线");
                return;
            }
            try
            {
                m_arListDepartureBarcodes.Clear();
                OpenFileDialog ofdg = new OpenFileDialog();
                if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string file = ofdg.FileName;//得到选择的文件的完整路径
                    totalCount = 0;
                    m_arListDepartureBarcodes = UtilityHelp.Instance.getBarCodeFromFile(file, out totalCount);
                    if (m_arListDepartureBarcodes.Count == 0)
                    {
                        MessageBox.Show("没有取到运单号");
                        return;
                    }
                    mbs_departure = null;
                    mbs_departure = new BindingSource();
                    m_htDepRoadMap.Clear();
                    m_ht_dep_filter.Clear();
                    m_dt_DepartureDelayed.Rows.Clear();
                    m_htCopyMap.Clear();
                    int curFileCount = 0;
                    StoParams.Instance.curParces = 0;
                    this.handleDtCopyDgv(curFileCount);
                    lblImportResult.Text = "导入条数：" + totalCount.ToString();
                    txbImport.Text = "导入条数：" + totalCount.ToString();
                    txtCurrentStatus.Text = "查询中";
                    anylizeWaybillCount = 0;
                    //JTDelayHelperNew.Instance.BeginAnalyThread(m_arListDepartureBarcodes, "departure");

                }
            }
            catch(Exception ex)
            {

            }

        }

        private void btnFailStatic_Click(object sender, EventArgs e)
        {
            try
            {
                StoParams.Instance.totalParcels = 0;
                StoParams.Instance.curParces = 0;

                ArrayList arListLeaveMsgWaybills = new ArrayList();

                string allContent = txtLSFail.Text.Trim();
                allContent = allContent.Replace("，", "");
                allContent = allContent.Replace(",", "");
                int curLoop = 0;

                logHelp.LogHelper.Instance.writeLog("开始解析揽收失败");

                if (allContent.Length > 16000)
                {
                    while (allContent.Length > 16000)
                    {
                        curLoop++;
                        char[] jt = "JT".ToCharArray();
                        int spintIndex = allContent.IndexOfAny(jt, 16000);
                        //string sub = allContent.Substring(0, allContent.IndexOfAny(jt, spintIndex));
                        string sub = allContent.Substring(0, spintIndex);
                        ArrayList atlitTmp = UtilityHelp.Instance.getInputBarcodesAndAddr(sub, new TaskBean());
                        arListLeaveMsgWaybills.AddRange(atlitTmp);
                        allContent = allContent.Substring(spintIndex);


                    }
                    if (allContent.Length > 13 && allContent.Length < 16000)
                    {
                        ArrayList atlitTmp = UtilityHelp.Instance.getInputBarcodesAndAddr(allContent, new TaskBean());
                        arListLeaveMsgWaybills.AddRange(atlitTmp);

                    }

                }
                else
                {
                    arListLeaveMsgWaybills = UtilityHelp.Instance.getInputBarcodesAndAddr(txtLSFail.Text.Trim(), new TaskBean());
                }
                logHelp.LogHelper.Instance.writeLog("解析到个数：" + arListLeaveMsgWaybills.Count.ToString());
                //arListLeaveMsgWaybills = UtilityHelp.Instance.getInputBarcodesAndAddr(txtCJWaybills.Text.Trim());
               

                lblImportResult.Text = "输入条数：" + arListLeaveMsgWaybills.Count.ToString();
                txbImport.Text = "输入条数：" + arListLeaveMsgWaybills.Count.ToString();
                txtLSInfo.Text = "待解析揽收条数：" + arListLeaveMsgWaybills.Count.ToString() + " "; ;
                if (arListLeaveMsgWaybills.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    m_arListDisplayBarcodes.Clear();
                    foreach (ParcelBean parcelBean in arListLeaveMsgWaybills)
                    {
                        sb.AppendLine(parcelBean.wayBill);
                        m_arListDisplayBarcodes.Add(parcelBean.wayBill);
                    }

                    this.txtBarcodes.Text = sb.ToString();
                }



                rchRoadMap.Text = "开始解析揽收失败单号...";
                LanshouFailGen.Instance.BeginAnalyThread(arListLeaveMsgWaybills, "manual");
                //LeaveMessageHelperGen.Instance.BeginAnalyThread(arListLeaveMsgWaybills, "manual");
                rxtWaybills.Text = "";
            }
            catch(Exception ex)
            {

            }
        }

        private void tabControl3_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            try
            {
                string tabName = tabControl3.SelectedTab.Text;

                if(tabName.Contains("扫描")|| tabName.Contains("发件") || tabName.Contains("揽收"))
                {
                    tabControl1.SelectedIndex = 3;
                }


            }
            catch(Exception ex)
            {

            }
        }

        private void btnImportMain_Click(object sender, EventArgs e)
        {
            try
            {
                string path = @"";
                OpenFileDialog ofdg = new OpenFileDialog();
                if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    path = ofdg.FileName;//得到选择的文件的完整路径
                }
                else
                {
                    return;
                }


                StoParams.Instance.totalPages = 0;
                StoParams.Instance.curPage = 0;
                //string path = @"C:\Users\才子\Desktop\邻\0801\散货时效836f1d45-f4c4-4b57-bd22-e3126fa27c55 (1).xlsx";
                Worksheet sheet1 = UtilityExcel.Instance.GetWorksheet(path, 0);
                int rowCount = sheet1.Cells.Rows.Count;
                if (rowCount < 100)
                {
                    MessageBox.Show("干线时效加载异常");
                    return;
                }

                ArrayList arListSh = LoadBasicHelper.Instance.loadExcelMainLineData(sheet1, rowCount);


                StringBuilder sb = new StringBuilder();
                ArrayList arListZcBeans = new ArrayList();
                MessageBox.Show("干线路线加载完成 , 导入线路:"+ arListSh.Count.ToString());
                txtDelayHeader.Text = "干线路线加载完成 , 导入线路:" + arListSh.Count.ToString();
                //LoadBasicHelper.Instance.BeginLoadThread();
            }
            catch(Exception ex)
            {
                MessageBox.Show("导入干线失败 "+ex.ToString());
            }
        }

        private void menuTerminalStatic_Click(object sender, EventArgs e)
        {
            try
            {
                if (MemberInfo.Instance.token == "")
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }
                //临时
                if (!StoParams.Instance.isRegByMachine)
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }

                m_arListDepartureBarcodes.Clear();
                OpenFileDialog ofdg = new OpenFileDialog();
                if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string file = ofdg.FileName;//得到选择的文件的完整路径
                    totalCount = 0;
                    m_arListDepartureBarcodes = UtilityHelp.Instance.getBarCodeFromFile(file, out totalCount);
                    if (m_arListDepartureBarcodes.Count == 0)
                    {
                        MessageBox.Show("没有取到运单号");
                        return;
                    }
                    mbs_departure = null;
                    mbs_departure = new BindingSource();
                    m_htDepRoadMap.Clear();
                    m_ht_dep_filter.Clear();
                    m_dt_DepartureDelayed.Rows.Clear();
                    m_htCopyMap.Clear();
                    int curFileCount = 0;
                    StoParams.Instance.curParces = 0;
                    this.handleDtCopyDgv(curFileCount);
                    lblImportResult.Text = "导入条数：" + totalCount.ToString();
                    txbImport.Text = "导入条数：" + totalCount.ToString();
                    txtCurrentStatus.Text = "查询中";
                    anylizeWaybillCount = 0;
                    TerminalMessageHelperInfo.Instance.BeginAnalyThread(m_arListDepartureBarcodes, "departure");
                }



             }
            catch(Exception ex)
            {

            }
        }

        private void menuSiteAndZC_Click(object sender, EventArgs e)
        {
            try
            {
                StoParams.Instance.curParces = 0;
                if (MemberInfo.Instance.token == "")
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }
                //临时
                if (!StoParams.Instance.isRegByMachine)
                {
                    MessageBox.Show("请先设置机器人在线");
                    return;
                }
                totalCount = 0;
                txtLeavedBarcodes.Text = "";
                txtFailedBarcodes.Text = "";
                ArrayList arListCurImport = new ArrayList();
                OpenFileDialog ofdg = new OpenFileDialog();
                if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string file = ofdg.FileName;//得到选择的文件的完整路径

                    arListCurImport = UtilityHelp.Instance.getBarCodeFromFile(file, out totalCount);
                    if (arListCurImport.Count == 0)
                    {
                        MessageBox.Show("没有取到运单号");
                        return;
                    }
                    int curFileCount = 0;

                    lblImportResult.Text = "导入条数：" + totalCount.ToString();
                    txbImport.Text = "导入条数：" + totalCount.ToString();

                    anylizeWaybillCount = 0;
                    ZCMessageHelperInfo.Instance.BeginAnalyThread(arListCurImport, "departure");

                }
            }
            catch (Exception ex)
            {

            }
        }

        private void btnFJ_Click(object sender, EventArgs e)
        {
            StoParams.Instance.totalParcels = 0;
            StoParams.Instance.curParces = 0;

            ArrayList arListLeaveMsgWaybills = new ArrayList();

            string allContent = rchFJ.Text.Trim();
            allContent = allContent.Replace("，", "");
            allContent = allContent.Replace(",", "");
            int curLoop = 0;

            logHelp.LogHelper.Instance.writeLog("开始解析发件单号");

            if (allContent.Length > 16000)
            {
                while (allContent.Length > 16000)
                {
                    curLoop++;
                    char[] jt = "JT".ToCharArray();
                    int spintIndex = allContent.IndexOfAny(jt, 16000);
                    //string sub = allContent.Substring(0, allContent.IndexOfAny(jt, spintIndex));
                    string sub = allContent.Substring(0, spintIndex);
                    ArrayList atlitTmp = UtilityHelp.Instance.getInputBarcodesAndAddr(sub, new TaskBean());
                    arListLeaveMsgWaybills.AddRange(atlitTmp);
                    allContent = allContent.Substring(spintIndex);


                }
                if (allContent.Length > 13 && allContent.Length < 16000)
                {
                    ArrayList atlitTmp = UtilityHelp.Instance.getInputBarcodesAndAddr(allContent, new TaskBean());
                    arListLeaveMsgWaybills.AddRange(atlitTmp);

                }

            }
            else
            {
                arListLeaveMsgWaybills = UtilityHelp.Instance.getInputBarcodesAndAddr(rchFJ.Text.Trim(), new TaskBean());
            }
            logHelp.LogHelper.Instance.writeLog("解析到个数：" + arListLeaveMsgWaybills.Count.ToString());
            //arListLeaveMsgWaybills = UtilityHelp.Instance.getInputBarcodesAndAddr(txtCJWaybills.Text.Trim());
            rchFJ.Text = rchFJ.Text.Replace("，", ",");
            if (rchFJ.Text.Trim().Contains(","))
            {
                rchFJ.Text = rchFJ.Text.Replace(",", "\n");
            }
            //arListLeaveMsgWaybills.AddRange(txtCJWaybills.Text.Trim().Split('\n'));

            lblImportResult.Text = "输入条数：" + arListLeaveMsgWaybills.Count.ToString();
            txbImport.Text = "输入条数：" + arListLeaveMsgWaybills.Count.ToString();
            txtLSInfo.Text = "待揽收条数：" + arListLeaveMsgWaybills.Count.ToString() + " "; ;
            if (arListLeaveMsgWaybills.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                m_arListDisplayBarcodes.Clear();
                foreach (ParcelBean parcelBean in arListLeaveMsgWaybills)
                {
                    sb.AppendLine(parcelBean.wayBill);
                    m_arListDisplayBarcodes.Add(parcelBean.wayBill);
                }

                this.txtBarcodes.Text = sb.ToString();
            }



            rchRoadMap.Text = "开始发件...";
            FajianHelperGen.Instance.BeginAnalyThread(arListLeaveMsgWaybills, "manual");
            //LeaveMessageHelperGen.Instance.BeginAnalyThread(arListLeaveMsgWaybills, "manual");
            rchFJ.Text = "";
        }

        private void handleInvite(object roomidList)
        {
            try
            {
                ArrayList arRoomList = (ArrayList)roomidList;
                int curRoomCount = 0;
                foreach(string roomID in arRoomList)
                {

                    curRoomCount++;
                    ReplyHelper.Instance.inviteQWUserMsg(roomID, "", m_gewei, m_gewei);
                    LogHelper.Instance.writeLog("inivite: roomID=" + roomID.ToString()+" count="+ curRoomCount+"/ " + arRoomList.Count.ToString());
                    Random rd2 = new Random();
                    int randomNum = rd2.Next(8000, 15000);
                    if(curRoomCount%10==0)
                    {
                        randomNum = 30000;
                    }

                    System.Threading.Thread.Sleep(randomNum);
                }

            }
            catch(Exception ex)
            {

            }
           
        }
        private void btnBatchGroup_Click(object sender, EventArgs e)
        {
            try
            {
                m_gewei = "";
                m_gewei = txtCJWaybills.Text.Trim();
                if (m_gewei=="")
                {
                    return;
                }
               

                m_arListDepartureBarcodes.Clear();
                OpenFileDialog ofdg = new OpenFileDialog();
                if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string file = ofdg.FileName;//得到选择的文件的完整路径
                    totalCount = 0;
                    m_arListDepartureBarcodes = UtilityHelp.Instance.getRoomIDFromFile(file, out totalCount);
                  
                    mbs_departure = null;
                    mbs_departure = new BindingSource();
                    m_htDepRoadMap.Clear();
                    m_ht_dep_filter.Clear();
                    m_dt_DepartureDelayed.Rows.Clear();
                    m_htCopyMap.Clear();
                    int curFileCount = 0;
                    StoParams.Instance.curParces = 0;
                    this.handleDtCopyDgv(curFileCount);
                    lblImportResult.Text = "导入条数：" + totalCount.ToString();
                    txbImport.Text = "导入条数：" + totalCount.ToString();
                    txtCurrentStatus.Text = "查询中";
                    anylizeWaybillCount = 0;
                    if(m_arListDepartureBarcodes.Count>0)
                    {
                        Thread fThreadDep = new Thread(new ParameterizedThreadStart(handleInvite));
                        fThreadDep.Start((object)m_arListDepartureBarcodes);
                        fThreadDep.IsBackground = true;
                        fThreadDep.Start();
                    }
                    //JTDelayHelperNew.Instance.BeginAnalyThread(m_arListDepartureBarcodes, "departure");

                }



                /*string[] arr = txtCJWaybills.Text.ToString().Split('$');
                if(arr.Length==2)
                {
                    LogHelper.Instance.writeLog("btnBatchGroup_Click:" + txtCJWaybills.Text.ToString());

                    ReplyHelper.Instance.inviteQWUserMsg(arr[0], "", arr[1], arr[1]);
                    System.Threading.Thread.Sleep(5000);
                }*/
                


                //addDraw(this.txtCJWaybills.Text);
                //addCoding(this.txtCJWaybills.Text);
                //getGroupList(this.txtCJWaybills.Text);
                //getInterUser(this.txtCJWaybills.Text);
                //ReplyHelper.Instance.getInternalUserList(1, 50);


                for(int i=1;i<2;i++)
                {
                    //ReplyHelper.Instance.getGroupList(i, 50);
                    //System.Threading.Thread.Sleep(1500);
                }

            }
            catch(Exception ex)
            {

            }
        }


        private void addDraw(string content)
        {
            try
            {
                LogHelper.Instance.writeLog("draw  ");
                string[] arr = content.Split('\n');
                ArrayList arListNew = new ArrayList();
                arListNew.Add("1688856511366823");
                arListNew.Add("1688856511365542");
                arListNew.Add("1688854873453304");
                arListNew.Add("1688854535452199");
                arListNew.Add("1688857617398774");
                StringBuilder sb = new StringBuilder();
                foreach (string roomid in arr)
                {
                    sb.AppendLine("roomid:" + roomid);
                    foreach(string line in arListNew)
                    {
                        sb.AppendLine(line);
                    }

                }

                LogHelper.Instance.writeLog(sb.ToString());


            }
            catch(Exception ex)
            {

            }

        }


        private void addCoding(string content)
        {
            try
            {

                LogHelper.Instance.writeLog("coding  ");

                string[] arr = content.Split('\n');
                ArrayList arListNew = new ArrayList();
                arListNew.Add("1688855001433468");
                arListNew.Add("1688855943427177");
                arListNew.Add("1688857595482125");

                


                StringBuilder sb = new StringBuilder();
                foreach (string roomid in arr)
                {
                    sb.AppendLine("roomid:" + roomid);
                    foreach (string line in arListNew)
                    {
                        sb.AppendLine(line);
                    }

                }

                LogHelper.Instance.writeLog(sb.ToString());


            }
            catch (Exception ex)
            {

            }

        }

        private void getInterUser(string content)
        {
            try
            {

                string[] arr = content.ToString().Split(new string[] { "\"user_id\"" }, StringSplitOptions.None);
                StringBuilder sb = new StringBuilder();
                foreach (string strLine in arr)
                {
                    string newLine = strLine;
                    newLine = newLine.Replace("\"", "");
                    if (newLine.StartsWith(":"))
                    {
                        string left = newLine.Substring(newLine.IndexOf(':'), newLine.IndexOf(',') - newLine.IndexOf(':'));
                        left = left.Replace("\"", "");
                        if (MathUtility.ImpIsNum(left.Replace(":", "").Trim()) && left.Length > 15)
                        {
                            sb.AppendLine(left.Replace(":", "").Trim());
                        }

                    }
                }
                LogHelper.Instance.writeLog(sb.ToString());

            }
            catch(Exception ex)
            {

            }
        }


        private void getGroupList(string content)
        {
            try
            {

                string[] arr = content.ToString().Replace("\r\n","").Split(new string[] { "\"conversation_id\":" }, StringSplitOptions.None);
                StringBuilder sb = new StringBuilder();
                ArrayList arTmp = new ArrayList();
                foreach (string strLine in arr)
                {
                    string newLine = strLine;
                    newLine = newLine.Replace("\"", "");
                    if (newLine.StartsWith("R:"))
                    {
                        string left = newLine.Substring(newLine.IndexOf('R'), newLine.IndexOf(',') - newLine.IndexOf('R'));
                        left = left.Replace("\"", "");
                        if (MathUtility.ImpIsNum(left.Replace("R:", "").Trim()) && left.Length > 15)
                        {
                            if(!arTmp.Contains(left.Trim()))
                            {
                                arTmp.Add(left.Trim());
                                sb.AppendLine(left.Trim());
                            }
                            //sb.AppendLine(left.Trim());
                        }

                    }
                }
                LogHelper.Instance.writeLog(sb.ToString());

            }
            catch (Exception ex)
            {

            }
        }

        private void menuInboundFilterInter_Click(object sender, EventArgs e)
        {
            try
            {

            }
            catch(Exception ex)
            {

            }
        }
    }
}
